Answer the question
In order to leave comments, you need to log in
How to redirect with regular expression in htaccess?
Hello! There is a site on CMS ocStore 2.3. I need to make 301 redirects from these addresses:
https://site.ru/index.php?route=product/product&path=76&product_id=894/specification
https://site.ru/index.php?route=product/product&path=76&product_id=894
Redirect 301 /index.php?route=product/product&path=[0-9]&product_id=[0-9]/[0-9 a-z] /index.php?route=product/product&path=[0-9]&product_id=[0-9]
Answer the question
In order to leave comments, you need to log in
In theory it should have been like this
RewriteCond %{QUERY_STRING} (?:^|&)route\=product/product(?:$|&)
RewriteCond %{QUERY_STRING} (?:^|&)path\=([0-9]+)(?:$|&)
RewriteCond %{QUERY_STRING} (?:^|&)product_id\=([0-9]+)/specification(?:$|&)
RewriteRule ^index\.php$ /index.php?route=product/product&path=%1&product_id=%2 [L,R=301]
if after product_id=894 there is some value
product_id=[0-9]+[^0-9]
or product_id=\d+\D
RewriteCond %{QUERY_STRING} ^(route=product/product&path=\d+&product_id=\d+)\D
RewriteRule ^index\.php$ /index.php?%1 [R=301,L]
RewriteCond &%{QUERY_STRING}& ^(?=.*&(route=product/product)&)(?=.*(&path=\d+)&)(?=.*(&product_id=\d+)[^&\d])
RewriteRule ^index\.php$ /index.php?%1%2%3 [R=301,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question