我有一些像这样的网址:
index.php?cPath=23
index.php?cPath=23&sort=4a&language=En
index.php?currency=EUR&cPath=23&sort=4a&language=nl
index.php?currency=HUF&cPath=23&sort=4a&language=Hu我想把它们都重定向到这个链接:shop/food。所以我把这个放在我的htaccess文件中:
# 301 --- /index.php?*cPath=23* => /shop/food
RewriteCond %{QUERY_STRING} (^|&)cPath=23($|&)
RewriteRule ^index\.php$ /shop/food? [L,R=301]效果很好。
但是..。我还有些URL是这样的:
product_info.php?cPath=23&products_id=1324&language=En&osCsid=204giavieen8nmfv95b0dfrgs5使用上面的代码,这个链接也被重定向到/shop/food,因为cPath=23在链接中。
我现在正在寻找一个代码,它只在/shop/food在链接中时重定向到index.php。这样,所有这些链接都将被重定向,使用product_info.php?cPath=23的链接将得到一个404未找到的错误。
或者另一种方式,与product_info.php或products_id的链接将不会被重定向。
发布于 2014-07-30 21:22:25
您可以使用以下规则:
RewriteCond %{QUERY_STRING} (^|&)cPath=23($|&)
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php$ /shop/food? [L,R=301]确保这个位置就在RewriteEngine On下面。
On使用%{THE_REQUEST}: THE_REQUEST变量表示从浏览器接收到的原始请求,并且在执行某些重写规则后不会被覆盖。此变量的示例值为GET /index.php?id=123 HTTP/1.1。
https://stackoverflow.com/questions/25045291
复制相似问题