繁体   English   中英

htaccess 301通过剥离部分字符串url进行重定向以更正url

[英]Htaccess 301 redirect by stripping part of string url to correct url

请告知,我们在用玩具一节中为网站创建大量重复内容时出错,如何使用htaccess删除网址中的“品牌”和“位置”并重定向到正确的网址

例如。 正确的网址

   http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3

网址错误

 http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3&brand=1
 http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3&brand=1&location=delhi

正确的URL

   http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3&limitstart=45

网址错误

     http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3&brand=1&limitstart=45
     http://www.abc.com/index.php?option=com_toys&view=category&Itemid=3&brand=1&location=delhi&limitstart=45

如何在htaccess中创建301重定向,以便所有带有com_toys(带有品牌和/或位置)的url都可以被剥离并重定向到正确的url。

尝试:

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)option=com_toys(&|$)
RewriteCond %{QUERY_STRING} ^(.*)&brand=([^&]+)(.*)$
RewriteRule ^index\.php$ /index.php?%1%3 [L,R=301]

RewriteCond %{QUERY_STRING} (^|&)option=com_toys(&|$)
RewriteCond %{QUERY_STRING} ^(.*)&location=([^&]+)(.*)$
RewriteRule ^index\.php$ /index.php?%1%3 [L,R=301]

在文档根目录中的htaccess文件中,最好在您已有的所有规则之上。

暂无
暂无

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

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