.htaccess htaccess通过添加参数重定向url

.htaccess htaccess通过添加参数重定向url,.htaccess,redirect,.htaccess,Redirect,需要通过htaccess匹配特定格式的301重定向Url的指导吗 Existing URL http://www.example.com/index.php?option=com_toys&limitstart=20 Proposed URL http://www.example.com/index.php?option=com_toys&view=list&Itemid=2&limitstart=20 在这里,limitstart可能会更改为0、20、4

需要通过htaccess匹配特定格式的301重定向Url的指导吗

Existing URL

http://www.example.com/index.php?option=com_toys&limitstart=20

Proposed URL

http://www.example.com/index.php?option=com_toys&view=list&Itemid=2&limitstart=20
在这里,limitstart可能会更改为0、20、40、60甚至1000,因此在新提议的url中也应该保持不变


是否有人建议使用上面的htaccess进行重定向?您需要使用
RewriteCond
匹配查询字符串,使用正则表达式捕获这两个参数:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(option=com_toys)&(limitstart=\d+)$ [NC]
RewriteRule ^/?index\.php$ %{REQUEST_URI}?%1&view=list&Itemid=2&%2 [L,NC,R=301]

这听起来更像是PHP问题,而不是
.htaccess
问题。你不是正在通过
Itemid
view
作为
\u获取
参数吗?我是,但不幸的是,Google crawl已经像现有的url一样抓取了一些页面,为了实现同步-正在考虑htaccess解决方案,以便以与建议的url相同的格式重定向所有内容。您好,谢谢-但其显示的url不正确:-
http://www.example.com/index.php?view=list&Itemid=2&option=com_toys&limitstart=120
而不是
http://www.example.com/index.php?option=com_toys&view=list&Itemid=2&limitstart=120
实际上是同一个URL,只是参数的顺序不同。这会影响搜索,因为Google crawl会将其视为重复的URL,是否可以以相同的顺序获取参数