CakePHP htaccess在本地运行站点时重定向到实时站点

时间:2012-05-31 17:29:11

标签: .htaccess cakephp

我正在使用CakePHP的网站上工作。我需要开始为这个网站添加一些功能,所以我从现场网站到我的开发机器(使用MAMP服务器的mac os lion)中提取所有内容。当我尝试加载网站(localhost / example.com /)时,它会自动将我重定向到实际网站(www.example.com)。

以下是根htaccess文件内容:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{HTTP_HOST}   !^$
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

当我评论前两个 RewriteCond第一个 RewriteRule时,我的机器会抛出500内部服务器错误而没有apache / php记录输出。

如何在本地运行本网站而不自动重定向到实际网站?

我可以提供任何其他信息吗?

编辑:这是我的document_root:/Applications/MAMP/htdocs。不应该是/Applications/MAMP/htdocs/example.com吗? 编辑:这是/webroot/.htaccess文件:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule img/([0-9]*x[0-9]*)/(.*)/(.*)$ files/image/$2/$1/$3 [QSA,L]
    RewriteRule (js|css)/vendors/(.*)$ vendors.php?type=$1&file=$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

AddType application/x-javascript .js
AddType text/css .css

<IfModule mod_deflate.c>
  # compress content with type html, text, and css
  AddOutputFilterByType DEFLATE text/css text/javascript application/javascript application/x-javascript text/js

  SetOutputFilter DEFLATE
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

  # Don't compress images/flash 
  SetEnvIfNoCase Request_URI \
  \.(?:swf|flv)$ no-gzip dont-vary

  # Don't compress images
  # SetEnvIfNoCase          Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  # SetEnvIfNoCase          Request_URI \/image\.php no-gzip dont-vary

  # Also don't compress PDF and Flash-files 17-01-2004 MM
  SetEnvIfNoCase          Request_URI \.pdf$ no-gzip dont-vary

  <IfModule mod_headers.c>
    # properly handle requests coming from behind proxies
    Header append Vary User-Agent
  </IfModule>
</IfModule>

<IfModule mod_expires.c> 
  ExpiresActive On
  ExpiresByType text/css "access plus 10 years"
  ExpiresByType text/js "access plus 10 years"
  ExpiresByType text/javascript "access plus 10 years"
  ExpiresByType application/x-javascript "access plus 10 years"
  ExpiresByType application/javascript "access plus 10 years"
  ExpiresByType image/png "access plus 10 years"
  ExpiresByType image/gif "access plus 10 years"
  ExpiresByType image/jpeg "access plus 10 years"
  ExpiresByType video/x-flv "access plus 10 years"
</IfModule>

FileETag none
<IfModule mod_headers.c>
# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>
</IfModule>

编辑:我已经为apache启用了调试日志记录级别,因此我可以看到更多日志消息。这是访问项目根目录时的日志详细信息,错误为500:

[Fri Jun 01 11:00:35 2012] [debug] mod_deflate.c(615): [client ::1] Zlib: Compressed 0 to 2 : URL /example.com/webroot/index.php

[Fri Jun 01 11:00:35 2012] [debug] mod_headers.c(756): headers: ap_headers_output_filter()

我在访问网站时也包含了access_log数据,错误为500:

127.0.0.1 - - [01/Jun/2012:11:03:02 -0400] "GET /example.com/ HTTP/1.1" 500 20 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.53 Safari/536.5"

1 个答案:

答案 0 :(得分:0)

用以下内容替换现有的.htaccess代码:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /example.com/

    RewriteRule (?!^webroot/)^(.*)$ webroot/$1 [L]
</IfModule>