2014-03-07 119 views
0

我有這段代碼,將domain.com/Birthdays/birthdays.php?n=Something轉換爲domain.com/Birthdays/Something,併爲其他頁面取下.php和.html文件:.htaccess代碼給出的錯誤500

RewriteEngine on 
RewriteRule ^Birthday/(\w+)$ /Birthdays/birthdays.php?n=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 

問題是當我補充一點:

RewriteEngine on 
RewriteRule ^Birthdays/(.*)$ [L] 
RewriteRule ^Birthday/(\w+)$ /Birthdays/birthdays.php?n=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 

它給了我一個錯誤(500),但如果我改變對(\ w +),它的工作原理(*)。但我不想那樣。

回答

0

您可以使用:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^Birthday/(\w*)$ /Birthdays/birthdays.php?n=$1 [L,QSA] 

你得到500由於循環錯誤爲您的規則的模式匹配起點和重寫的URI。