请参阅以下三个网址
1)www.example.com/product/anystring/
2)www.example.com/product/selected/
3)www.example.com/product-all/
此处允许的产品网址为 www.example.com/product/selected / ,其中包含元素 id 。因此,产品允许的网址类似于 www.example.com/product/selected/?id=1 , www.example.com/product/selected/?id=2 , www.example.com/product/selected/?id=3 等
所以请参阅第一个URL www.example.com/product/ 字符串 /。
因此,在乘积之后/ string即将出现。因此是不允许的。
因此,如果有人输入www.example.com/product/anystring/我需要重定向到www.example.com/product-all/。我该怎么做?
示例
1) www.example.com/product/selected/?id=3 (no redirection needed )
2) www.example.com/product/selected/?id=14 (no redirection needed )
3) www.example.com/product/selected/?id=24 (no redirection needed )
4) www.example.com/product/test/ need redirection to www.example.com/product-all/
5) www.example.com/product/pen/ need redirection to www.example.com/product-all/
6) www.example.com/product/apple/ need redirection to www.example.com/product-all/
答案 0 :(得分:0)
您可以将此规则用作最高规则:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^product/[\w-]+)/?$ /product-all/ [L,NC,NE,R=301]
# other rules go here