2012-10-03 89 views
1

我在與mod_rewrite的一個問題,我認爲可能會在除了我的.htaccess一些其他配置文件中的全局規則造成的,需要看是否有顯示所有的方式有效的RewriteRules。顯示在阿帕奇/ PHP的所有活動的RewriteRules

具體來說,我的問題是http://mydomain.com/pages/test工作正常(重定向到pages/index.php),但http://mydomain.com/pages/test-page返回404錯誤。任何在頁面/中斷後包含破折號的內容。其他一切正常。重寫規則應該是:如果找到/pages/file.xx,則顯示它。否則,將其發送到/pages/index.php

我的.htaccess

 

RewriteEngine On 
RewriteBase /pages 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule . - [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(am-.*) $2 [L] 
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule (.*)$ /pages/$1/ [R=301,L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-zA-Z0-9\-_\/\s]+)/?$ /pages/index.php [L] 

編輯 隨着RewriteLog打開,我得到以下URL 「domain.com/pages/test-string」 :

 
xx.xx.xx.xx - - [03/Oct/2012:11:34:15 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/pages/test-string 
xx.xx.xx.xx - - [03/Oct/2012:11:34:16 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/splash/test-string 

下面是URL結果 「domain.com/pages/test」

 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] rewrite test -> /pages/test/ 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] explicitly forcing redirect with http://domain.com/pages/test/ 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] trying to replace prefix /hsphere/local/home/domain/domain.com/pages/ with /pages 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] escaping http://domain.com/pages/test/ for redirect 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] redirect to http://domain.com/pages/test/ [REDIRECT/301] 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] rewrite test/ -> /pages/index.php 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (2) [per-dir /hsphere/local/home/domain/domain.com/pages/] trying to replace prefix /hsphere/local/home/domain/domain.com/pages/ with /pages 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#172fe530/initial] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] internal redirect with /pages/index.php [INTERNAL REDIRECT] 
xx.xx.xx.xx - - [03/Oct/2012:11:37:46 -0400] [domain.com/sid#17b39d20][rid#17c144e0/initial/redir#1] (1) [per-dir /hsphere/local/home/domain/domain.com/pages/] pass through /hsphere/local/home/domain/domain.com/pages/index.php 
+0

'重寫規則。 - [L]'應該是'重寫規則。* - [L]'爲了清晰恕我直言。在最後一個字符類*了'\ s'應該*是多餘的,因爲在它字面空白字符的URL *應*導致400錯誤,也'/'不需要在mod_rewrite的正則表達式,因爲要進行轉義它不使用明確的分隔符。我懷疑這些問題中的任何一個都不能解決問題,只是一般性評論。這個.htaccess文件位於哪裏? – DaveRandom

+0

這個.htaccess文件位於/ pages /子目錄中。 (這是一個WordPress網站的一個子網站,所以可能根/.htaccess文件是影響它,但是我試着刪除根/.htaccess,它仍然有這使我認爲這個問題是上漲的問題在httpd.conf或站點特定site.conf文件 –

+0

那麼在我看來,文件中有太多的邏輯,例如你的第一條規則聲稱,如果文件存在,它將直接提供服務,但以下幾種規則仍然繼續斷言該文件不存在,你可以用去除一些膨脹的做,我想,它可能使問題更容易看到的。如果在根去除.htaccess文件並不影響它,它是不太可能有任何其他規則參與了這個問題 – DaveRandom

回答

1

添加RewriteLog和RewriteLogLevel線。我會從日誌級別2或3開始,因爲它可能會很長。

+0

隨着RewriteLog打開,它似乎正在嘗試通過破折號的項目:[per-dir /hsphere/local/home/domain/domainname.com/pages/]通過/ hsphere /本地的/ home /域名/ domainname.com /頁/測試串 –