Reputation: 93
In a multilingual website I am trying to set a rule in .htaccess, so that the URLs that are contained in a folder, and that are matching a prefix, are redirected into a sub-folder.
In concrete:
www.example.com/es/urlprefix*
==> www.example.com/es/subfolder/urlprefix*
Example:
www.example.com/es/urlprefix_example
is redirected to
www.example.com/es/subfolder/urlprefix_example
I would also like to know how to do the reverse, that is:
www.example.com/es/subfolder/urlprefix*
==> www.example.com/es/urlprefix*
Upvotes: 0
Views: 601
Reputation: 1201
Try the following at the top of your .htaccess
file to redirect to the subfolder:
RewriteEngine On
RewriteRule ^(es)/(urlprefix.*) /$1/subfolder/$2 [R,L]
To redirect the other way (to remove the subfolder) you could do something like this:
RewriteRule ^(es)/subfolder/(urlprefix.*) /$1/$2 [R,L]
Obviously you can't do both at the same time, without some additional conditions, otherwise you'll get a redirect loop.
Upvotes: 2