具有匹配字符串的url的Htaccess重定向

时间:2013-09-19 09:52:52

标签: .htaccess redirect

在oldtoys

中为所有字符串匹配'start'参数的301重定向需要帮助

生成的网址不正确

http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&start=45&limitstart=300
http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&start=30&limitstart=275
http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&start=15&limitstart=250

更正网址

http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&limitstart=300
http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&limitstart=275
http://www.abc.com/index.php?option=com_oldtoys&view=category&Itemid=2&limitstart=250

这仅适用于旧玩具组件 有人可以帮忙吗

2 个答案:

答案 0 :(得分:2)

使用mod_rewrite:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(option=com_oldtoys&.*)&start=[0-9]+(.*)$
RewriteRule ^index\.php$ /index.php?%1%2 [L,R=301]

答案 1 :(得分:1)

您可以使用此规则:

RewriteCond %{QUERY_STRING} ^(option=com_oldtoys&view=category&Itemid=[^&]*)&start=[^&]*&(limitstart=[^&]*) [NC]
RewriteRule ^index\.php$ $0?%1&%2 [L,NC,R=301]