2016-04-14 57 views
1

我無法設置以下301重定向。.htaccess幫助 - 301重定向URL的特殊字符

我試圖重定向:

https://www.example.com/blog/wp-includes/js/jquery/jquery.js?ver=1.11.3 

到主頁:

https://www.example.com/ 

這是我試過,但不起作用。

Redirect 301 "/blog/wp-includes/js/jquery/jquery.js\?ver\=1\.11\.3" "/" 

回答

0

查詢字符串是不匹配的重定向指令的一部分,你需要來匹配%{THE_REQUEST}使用國防部重寫,請嘗試:

RewriteEngine on 

RewriteCond %{THE_REQUEST} /blog/wp-includes/js/jquery/jquery\.js\?ver=1\.11\.3 [NC] 
RewriteRule^/? [L,R] 

您可以刪除?如果您想要將查詢字符串轉錄到主頁,請從目標路徑中輸入

1

由於此頁https://simonecarletti.com/blog/2009/01/apache-query-string-redirects/

上註明不幸的是,Redirect也不RedirectMatch允許您指定的重定向源的查詢字符串。

所以,你必須切換到使用mod_rewrite,即用這個代替:

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/blog/wp-includes/js/jquery/jquery\.js$ 
RewriteCond %{QUERY_STRING} ^ver=1\.11\.3$ 
RewriteRule ^(.*)$/[R=301,L]