Reputation: 115
I can't seem to figure out how to do my redirects correctly with my htaccess.
I need to redirect somes pages like this (xxx means any string):
website.com/fr
=> OKwebsite.com/en
=> website.com/en/page-1
[R 301]website.com/en/category-1/xxx
=> OKwebsite.com/en/category-2/xxx
=> website.com/en/page-1
[R 301]website.com/en/category-3/xxx
=> website.com/en/page-1
[R 301] (I have multiple different categories with subpages that all need to be redirected).I've tried to figure this out with Apache's module_rewrite by looking at other examples online and also the docs. I've tried something like this (but it didn't work):
RewriteCond %{REQUEST_URI} ^en/$ [OR]
RewriteCond %{REQUEST_URI} ^en/category-2$ [OR]
RewriteCond %{REQUEST_URI} ^en/category-3$ [OR]
RewriteRule (.*) https://website.com/en/page-1 [L,R=301]
Upvotes: 1
Views: 246
Reputation: 133428
Could you please try following, written as per shown samples. Please clear your browser cache after placing these in your htaccess file.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(en)/?$ [NC]
RewriteRule ^(.*)$ /%1/page-1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/(category-[23])/[\w-]+/?$ [NC]
RewriteRule ^(.*)$ /en/page-1 [R=301,L]
Upvotes: 2