繁体   English   中英

htacess重定向-更改URL的查询部分

[英]htacess redirect - changing the query part of a URL

Google选择了以下URL并对其进行了排名:

http://www.example.com/yyy/zzz-99.php?item_id=99&sort=1 (不应该存在item_id = 99部分)。

由于我发现并修复了该错误,因此将以下行添加到了htaccess中:

RedirectPermanent /yyy/zzz-99.php?item_id=99&sort=1 http://www.example.com/yyy/zzz-99.php?&sort=1

但是,该重定向不起作用。 关于我在做什么错的任何线索吗?

我认为您甚至需要mod_rewrite来实现该单个替换,因为其中包括一个查询字符串。

您可以在根目录的.htaccess文件中尝试此操作,前提是启用了mod_rewrite:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}   ^/yyy/zzz-99\.php  [NC]
RewriteCond %{QUERY_STRING}  item_id=99&sort=1  [NC]
RewriteRule .*        /yyy/zzz-99.php?&sort=1?  [NC,L,R=301]

重新导向

http://www.example.com/yyy/zzz-99.php?item_id=99&sort=1

http://www.example.com/yyy/zzz-99.php?&sort=1

对于静默映射,从[NC,L,R = 301]中删除R = 301。

检查您的.htaccess文件的名称。 确保它以句点开头。

redirect 301 /index.html http://www.domain.com/index.html 
redirect permanent /index.html http://www.domain.com/index.html 
redirectpermanent /index.html http://www.domain.com/index.html

在.htaccess中使用301重定向:

重定向301 http://www.example.com/yyy/zzz-99.php?item_id=99&sort=1 http://www.example.com/yyy/zzz-99.php?sort=1

重定向301(从)(至)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM