Reputation: 97
I'm currently using a RewriteRule to redirect a subfolder called /shop/ to root of new site which works perfectly.
RewriteRule ^shop/?(.*)$ /$1 [L,NC,R=301]
I now want to include a condition above that can match a path like below
old site - www.domain.com/shop/brand-name
and rewrite it to:
new site - www.domain.com/brands/brand-name
where it matches on the brand-name part and performs a 301 redirect. Can mod_rewrite do this? It's important it matches on the brand-name effectively swapping /shop/ for /brands/ but not effecting the RewriteRule I have above because that works perfectly for everything else. Thanks in advance...
Upvotes: 0
Views: 715
Reputation: 47945
Maybe I got you wrong but this should work:
RewriteRule ^shop/brand-name$ /brands/brand-name [L,NC,R=301]
RewriteRule ^shop/?(.*)$ /$1 [L,NC,R=301]
The trick is that you add the new rule before your existing rule. Together with the L option you avoid that your other rules are executed.
If you have multiple bands (what I expect) than you can list them this way:
RewriteRule ^shop/(brand-name|other-brand|third-brand)$ /brands/$1 [L,NC,R=301]
Upvotes: 0