2013-10-11 38 views
1

我想重寫URL像爲什麼我的重寫規則沒有重定向給出500錯誤?

mysite.com/eng?sentence=cat 

顯示,如:

mysite.com/eng/cat 

我不想重定向只是一個重寫。所以我試圖改變重寫規則,我發現,示例性前我編輯它在它有一個R = 301原本:

RewriteCond %{THE_REQUEST} ^GET\ /eng\?sentence=([^&\s]+) [NC] 
RewriteRule ^eng\?sentence=$ /english/%1? [R=302,NC,L] 

但是當我從第二線除去R = 301,它提供了500錯誤。

我該怎麼寫這種重寫規則?我不是偉大與此正則表達式的東西,我也不是熟悉

我htaccess文件:

# Use PHP5.3 Single php.ini as default 
AddHandler application/x-httpd-php54s .php 
AddType application/x-httpd-php .htm .html 

Options -Indexes -MultiViews 

ErrorDocument 404 /404.php 
ErrorDocument 500 /500.php 

RewriteEngine on 

RewriteCond %{THE_REQUEST} ^GET\ /eng\?sentence=([^&\s]+) [NC] 
RewriteRule ^eng\?sentence=$ /english/%1? [R=302,NC,L] 



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

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> 
    Header set Cache-Control "max-age=604800, public" 
</FilesMatch> 

回答

0

使用行尾錨$否則只是RewriteCond

RewriteCond %{THE_REQUEST} ^GET\s/eng\?sentence=([^&\s]+) [NC] 
RewriteRule^/eng/%1? [NC,L,R=302] 

最有可能的500回覆是因爲你的.htaccess中的其他規則循環。我建議你在你的問題中發佈完整的.htaccess代碼。

+0

你的版本也給了我500錯誤,所以我在我的編輯中發佈了我的htaccess內容。 – user1397417

+0

你可以**註釋掉**'ErrorDocument'行和重新測試嗎? – anubhava

+0

你有機會通過'註釋掉兩個ErrorDocument行'來測試這個嗎? – anubhava