2017-07-15 63 views
0

我喜歡做以下重定向:301使用查詢字符串重定向網址?

domain.de/?file=team - >domain.de/team.html

要做到這一點,我嘗試以下方法改寫(即is'nt working):

RewriteCond %{QUERY_STRING} ^file=team$ 
RewriteRule ^/$ /team.html [L,R=301] 

我該如何做301重定向?

回答

0

得到解決由我自己:

RewriteCond %{QUERY_STRING} ^file=team$ 
RewriteRule ^$ /team.html? [L,R=301] 

domain.de/?file=team - > domain.de/team.html

如果你看到上面我的問題我犯了以下兩個錯誤:

1.錯誤:缺少問號

如果刪除了問號,則QUERY_STRING不會被刪除:

RewriteRule ^$ /team.html [L,R=301] 

domain.de/?file=team - > domain.de/team.html?file=team

通過命令RedirectMatch無法刪除query_strings的方式提供了進一步的提示。

2.錯誤:錯誤的重寫路徑

RewriteRule ^\$ ... does not match doamin.de/?file=team 
RewriteRule ^$ ... matches 
+0

的'^/$'正則表達式不起作用,因爲前綴(斜線)在以每個處理規則時,被剝離的路徑目錄上下文,就像在''容器中一樣。通過擴展,htaccess文件中的所有規則都是每個目錄,因爲它們應用於htaccess文件所在目錄的上下文中。 –

+0

您的評論刺激了我,因爲我沒有寫過'^/$'...我寫了'^\ $' –

+0

你的問題說:「'重寫規則^/$ /team.html [L,R = 301]'' –