2010-07-18 130 views
2

這是htaccess的我: 選項+的FollowSymLinks的.htaccess似乎被忽略的RewriteCond

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/pages 
RewriteRule ^(.+)/$ /$1 [NC] 
RewriteRule ^$ /pages/index.php [NC] 
RewriteRule ^([a-z]+)\?([^/]+)$ /pages/$1.php?$2 [NC] 
RewriteRule ^([a-z]+)/([^/]+)$ /pages/$1.php?q=$2 [NC] 
RewriteRule ^([a-z]+)$ /pages/$1.php [NC] 
ErrorDocument 404 /pages/404.php 

什麼是應該做的是很簡單:從URL

  • 刪除斜線
  • direct example.com/tomato to example.com/pages/tomato.php
  • direct example.com/tomato?c=red & size = big to example.com/pages/ ?tomato.php C =紅色&大小=大
  • 直接example.com/tomato/red到example.com/pages/tomato.php?q=r

但是這就是問題所在:任何URL for /pages/tomato.php匹配.htaccess的第7行,這會產生無限循環。這就是爲什麼我添加/頁的例外,但它似乎被忽略 - 我仍然得到這個日誌消息500內部服務器錯誤:

mod_rewrite的:達到內部重定向的最大數量。假設配置錯誤。如果需要,使用'RewriteOptions MaxRedirects'來增加限制。

這可能與我與虛擬主機一起運行這個事實有關嗎?如果是這樣,應該做些什麼來解決它?

回答

4

RewriteCond僅適用於下一個RewriteRule,因此您必須爲每個規則複製該條件。

+0

謝謝,是有辦法,使其適用於所有以下規則沒有一次又一次地複製嗎? – jorenl 2010-07-18 21:43:44

0

你可以在你的其他規則前用破規則:

RewriteRule ^pages/ - [L] 
+0

謝謝。事實證明,在這種情況下,僅將RewriteCond添加到另一個RewriteRule就足夠了,但我一定會記住這一點。 – jorenl 2010-07-20 21:19:42