简体   繁体   English

使用htaccess重定向查询网址

[英]Using htaccess to redirect query urls

I need to redirect a multiple urls within a few different categories using htaccess. 我需要使用htaccess在几个不同类别中重定向多个URL。 The current structure is; 当前的结构是;

.com/category/subcat/product.html?querystring=123 .com / category / subcat / product.html?querystring = 123

And I need all versions of the querystring URL to redirect to; 我需要所有版本的querystring URL重定向到;

.com/product.html .com / product.html

I don't mind writing a few lines for multiple categories but there are 1000's of variations of the querystring and cannot write all of them out. 我不介意为多个类别写几行,但是查询字符串有1000多种变体,因此无法全部写出来。

Anyone have any ideas?? 有人有想法么??

Try adding this to the htaccess file in your document root: 尝试将其添加到文档根目录下的htaccess文件中:

RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)querystring=123(&|$)
RewriteRule ^category/subcat/product\.html$ /product.html? [L,R=301]

As for the variations, if it's just a matter of a different numeric ID, then you can use: 至于变体,如果只是一个不同的数字ID,那么您可以使用:

RewriteCond %{QUERY_STRING} (^|&)jewelry_(metal|carat|colour|clarity)=[0-9]+(&|$)

If the "product" part is supposed to be variable, then replace the line with the rule with: 如果“产品”部分应该是可变的,则用以下规则替换该行:

RewriteRule ^category/subcat/(.+)\.html$ /$1.html? [L,R=301]

If "category" and "subcat" can be anything then: 如果“类别”和“子类别”可以是任意值,则:

RewriteRule ^[^/]+/[^/]+/(.+)\.html$ /$1.html? [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM