I need to modify my .htaccess in order to perfom the next redirect:
http://www.example.com/en/region1/subregion1/subregion2
to
http://www.example.com/en/example.php?param1=region1¶m2=subregion1¶m3=subregion2
The problem for me is that the original URL can have this 3 different structures:
/region1/
/region1/subregion1/
/region1/subregion1/subregion2
What I want is to convert this subdirectories in variables, whether they are 3 or only 1.
How can I achieve this with mod_rewrite?
Thank you
Take this as a base:
RewriteEngine on
RewriteRule ^en/(([^/]+)/)(([^/]+)/)?(([^/]+)/)?$ example.php?param1=$2¶m2=$4¶m3=$6
URL with only one param will be targeted to
example.php?param1=region1¶m2=¶m3=
So, non-existing params will be empty.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.