2016-04-14 55 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]