另一个HTAccess重写问题,抱歉....
我正在尝试重写所有具有menuid=28421,menuid=27384和menuid=73841的URL。问题是 menuid 是较长查询字符串的一部分,但并非所有参数都存在于查询字符串中。我只想根据menuid的值重写,而忽略其他参数。
http://www.domain.com/shop.php?menuid=28421&menuref=Ja&menutitle=New+Products&limit=5&page=8
http://www.domain.com/shop.php?menuid=27384&menuref=Ic&menutitle=Old+Products&page=3
http://www.domain.com/shop.php?menuid=73841&menuref=Hd&limit=10&page=14
重定向的结果:
http://www.domain.com/new.html
http://www.domain.com/old.html
http://www.domain.com/sale.html
在下面尝试了这个,但没有骰子:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^menuid=28421$ [NC]
RewriteRule ^shop'.php$ http://www.domain.com/new.html? [R=301,NE,NC,L]
我根据我的产品类别的menuid自动生成wegpages:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^menuid=28421&page=1$ [NC]
RewriteRule ^shop'.php$ http://www.domain.com/new.html? [R=301,NE,NC,L]
建议@anubhava增加:
## 301 Redirects of Individual Menus, Ignoring the Limit Parameter etc...
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)menuid=(?:28421|12356)(?:&|$) [NC]
RewriteRule ^shop'.php$ http://www.domain.com/new.html? [R=301,NE,NC,L]
谢谢你的任何建议,
马克。
在这种情况下
,您需要使用更好的正则表达式来匹配QUERY_STRING。
使用此规则:
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)(menuid=[^&]+).+ [NC]
RewriteRule ^shop'.php$ %{REQUEST_URI}?%1 [R=302,NE,NC,L]
menuidid=28421
可以出现在QUERY_STRING的任何位置。