2013-10-11 36 views
0

改寫像網頁:爲什麼我的重寫規則在最後放了一個問號?

mysite.com/eng/cat 

重定向到:

mysite.com/eng?sentence=cat 

我做了以下重寫規則:

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

但是當我要求

mysite.com/eng/cat 

它重寫這樣

mysite.com/eng?sentence=cat? 

我不知道爲什麼它把一個問號結尾,我也嘗試

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

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

這不作任何區別。任何幫助?

我htaccess文件:

# Use PHP5.3 Single php.ini as default 
AddHandler application/x-httpd-php54s .php 
RewriteEngine on  


RewriteCond %{THE_REQUEST} ^GET\s/+eng/([^/?&\s]+) [NC] 

重寫規則^英句子=%1 [R = 302,NC,L,NE]

AddType application/x-httpd-php .htm .html 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 



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

回答

0

就在這個規則應該工作:

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

請確保在不同的瀏覽器中進行測試,以避免301緩存陷阱。

確認工作正常後,將R=302更換爲R=301。避免在測試mod_rewrite規則時使用R=301(永久重定向)。

建議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\s/+eng/([^/?&\s]+) [NC] 
RewriteRule^/eng?sentence=%1 [R=302,NC,L,NE] 

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

使用Firefox瀏覽器重寫爲/英文句子=貓%3F – user1397417

+0

使用'NE'標誌見編輯? – anubhava

+0

仍然重寫爲eng?sentence = cat%3f – user1397417

相關問題