'apache .htaccess redirect regex
I need this redirect 301 rule in apache .htaccess:
/catalog/{category_slug}/{product_slug}
to
/product/{product_slug}
example:
/catalog/cat1/prod1 to /product/prod1
/catalog/cat1/prod2 to /product/prod2
/catalog/cat2/prod3 to /product/prod3
and also:
/en/catalog/abc/xyz to /en/product/xyz
/es/catalog/abc/xyz to /es/product/xyz
...
...
Could you please help me?
tks Simone
Solution 1:[1]
At the top of your root .htaccess file using mod_rewrite:
RewriteEngine On
RewriteRule ^catalog/[^/]+/([^/]+)/?$ /product/$1 [R=302,L]
The $1 backreference contains the "{product-slug}" (3rd path segment) from the capturing group in the preceding RewriteRule pattern.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MrWhite |
