RewriteCond to match query string parameters in any order

后端 未结 3 635
天涯浪人
天涯浪人 2020-12-02 19:35

I have a URL which may contain three parameters:

  1. ?category=computers
  2. &subcategory=laptops
  3. &product=dell-inspiron-15

I

3条回答
  •  时光取名叫无心
    2020-12-02 20:06

    1) In case You just need to check that all parameters are in url:

       RewriteCond %{QUERY_STRING} (^|&)category\=computers($|&)
       RewriteCond %{QUERY_STRING} (^|&)subcategory\=laptops($|&)
       RewriteCond %{QUERY_STRING} (^|&)product\=dell\-inspiron\-15($|&)
       RewriteRule ^$ http://store.example.com/computers/laptops/dell-inspiron-15/? [R=301,L]
    

    2) In case You need exact set of parameters:

     RewriteCond %{QUERY_STRING} ^&*(?:category\=computers|subcategory\=laptops|product\=dell\-inspiron\-15)(?!.*&\1(?:&|$))(?:&+(category\=computers|subcategory\=laptops|product\=dell\-inspiron\-15)(?!.*&\1(?:&|$))){2}&*$
     RewriteRule ^$ http://store.example.com/computers/laptops/dell-inspiron-15/? [R=301,L] 
    

    This rule is generated by 301 redirect generator

提交回复
热议问题