2011-03-09 51 views
1

什麼原因導致查詢字符串被分出, 導致/news/50在第二次運行中被附加(作爲下一個標誌N的影響)。Mod_rewrite:規則集導致奇怪的拆分並在重寫日誌中追加

我後面的行爲是將/about/news/50/重寫爲/about/news/news-item?post_id=50。 我添加了N標誌,因爲我想發送重寫的uri /about/news/news-item?post_id=50到index.php。

我在我的.htaccess文件下列規則:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule %{REQUEST_FILENAME} !-f 
RewriteRule %{REQUEST_FILENAME} !-d 
RewriteRule ^about/news/(\d+)/$ /about/news/news-item?post_id=$1 [QSA,N] 

RewriteRule ^index\.php$ - [QSA,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [QSA,L] 
</IfModule> 

日誌條目:

(2) init rewrite engine with requested uri /about/news/50/ 
(1) pass through /about/news/50/ 
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/ 
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/ 
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/' 
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/ 
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/ 
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'about/news/50/' 
(3) add path info postfix: /wordpress/about -> /wordpress/about/news/50/ 
(3) strip per-dir prefix: /wordpress/about/news/50/ -> about/news/50/ 
(3) applying pattern '^about/news/(\d+)/$' to uri 'about/news/50/' 
(2) rewrite 'about/news/50/' -> '/about/news/news-item?post_id=50' 
(3) split uri=/about/news/news-item?post_id=50 -> uri=/about/news/news-item, args=post_id=50 
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/ 
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/' 
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/ 
(3) applying pattern '%{REQUEST_FILENAME}' to uri '/about/news/news-item/news/50/' 
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/ 
(3) applying pattern '^about/news/(\d+)/$' to uri '/about/news/news-item/news/50/' 
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/ 
(3) applying pattern '^index\.php$' to uri '/about/news/news-item/news/50/' 
(3) add path info postfix: /about/news/news-item -> /about/news/news-item/news/50/ 
(3) applying pattern '.' to uri '/about/news/news-item/news/50/' 
(4) RewriteCond: input='/about/news/news-item' pattern='!-f' => matched 
(4) RewriteCond: input='/about/news/news-item' pattern='!-d' => matched 
(2) rewrite '/about/news/news-item/news/50/' -> '/index.php' 
(2) trying to replace prefix /wordpress/ with/
(1) internal redirect with /index.php [INTERNAL REDIRECT] 
(2) init rewrite engine with requested uri /index.php 
(1) pass through /index.php 
(3) strip per-dir prefix: /wordpress/index.php -> index.php 
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php' 
(3) strip per-dir prefix: /wordpress/index.php -> index.php 
(3) applying pattern '%{REQUEST_FILENAME}' to uri 'index.php' 
(3) strip per-dir prefix: /wordpress/index.php -> index.php 
(3) applying pattern '^about/news/(\d+)/$' to uri 'index.php' 
(3) strip per-dir prefix: /wordpress/index.php -> index.php 
(3) applying pattern '^index\.php$' to uri 'index.php' 
(1) pass through /wordpress/index.php 

回答

2

嘗試DPI(丟棄PATH_INFO標誌)如果你重寫了PATH_INFO剝離的URL從它,不希望它重新加入。這是每個目錄重寫的問題

編輯:如果你這樣做,由於WordPress的計數在PATH_INFO,你必須重新寫入/index.php/about/news/...讓下一個仍然可以看到PATH_INFO。

重寫規則^約/消息/(\ d +)/ $ /index.php/about/news/news-item?post_id=$1 [DPI,L]的 代替

重寫規則^約/消息/ (\ d +)/ $ index.php [DPI,L]