0

我正在使用 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()

在访问错误 500 的站点后,我还包含了 access_log 数据:

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"

4

1 回答 1

0

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

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

    RewriteRule (?!^webroot/)^(.*)$ webroot/$1 [L]
</IfModule>
于 2012-05-31T21:44:43.333 回答