【发布时间】:2013-11-07 10:43:26
【问题描述】:
另一个 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 自动生成网页:
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]
感谢您的建议,
标记。
【问题讨论】:
标签: php regex apache .htaccess mod-rewrite