2017-07-18 76 views
1

我有這個.htaccess文件和正常工作:創建多個重寫規則,不接受一個參數

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php? 
locale=$1&section=$2&action=$3&id=$4 [L] 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2&action=$3 [L] 
RewriteRule ^([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2 [L] 

但是,當我再添加一個線,一個單一的參數它爆炸。這是最後的文件:

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php? 
locale=$1&section=$2&action=$3&id=$4 [L] 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2&action=$3 [L] 
RewriteRule ^([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2 [L] 
RewriteRule ^([^/]*)$ /index.php?locale=$1 [L] 

這是錯誤消息:

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error. 

More information about this error may be available in the server error log. 

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. 

回答

0

你的服務器錯誤日誌將具有類似,

請求超過了10個內部重定向極限由於可能的配置錯誤。如果需要,使用'LimitInternalRecursion'來增加限制。使用'LogLevel debug'來獲得回溯。

這種情況發生時的mod_rewrite處理完一個URL,然後雙手回的URL語法分析器,然後執行它再次重寫規則,即使你有那些混賬[L]標誌上的第一次。前三種模式不匹配,但最後一種匹配。

對於你似乎在做,這是美化的網址,可能處理這個是簡單地忽略與index.php文件開始爲去年的規則路徑的最簡單的方法是什麼:

RewriteEngine On 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2&action=$3&id=$4 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2&action=$3 
RewriteRule ^([^/]*)/([^/]*)$ /index.php?locale=$1&section=$2 
RewriteCond %{REQUEST_URI} !^/index.php 
RewriteRule ^([^/]*)$ /index.php?locale=$1