Forum Moderators: phranque
Is it possible, with the help of .htaccess and mod_rewrite, to change the system so that
site.com/?variable1=name&variable2=age turns into
site.com/variable1=name,variable2=age or
site.com/name/age without me having to write it all "manually"? The rewrite rule I use now is:
RewriteRule ^([^/]+)/?([^/]+)?/?([^/]+)?/?$ index.php?att1=$1&att2=$2&att3=$3 [NC] With this, I'm only able to receive URLs and use their variables when they're formed like this:
site.com/variable1/variable2/variable3 But if I would do this:
site.com/variable1/variable2/variable3/variable4 $att4 won't be assigned "variable4", of course. So, what I'm wondering is if there is some way for .htaccess to do this for me - to allow infinite (or whatever the limit of query variables is) amounts of query variables in a pretty URL kind of way? I hope I've made myself clear.
Grateful for answers!
However, if you have server configuration (httpd.conf, conf.d, etc.) access, you can define and use a RewriteMap in mod_rewrite to call a PERL script to do this for you if that is easier overall than writing individual rules. For efficiency's sake, you may want to 'tag' the URLs which should be processed using this method, so that the RewriteMapped script is only invoked when necessary. For example, create another pseudo-directory level, and have URLs in this form: example.com/map_this/name1/value1/name2/value2
In this way, mod_rewrite can look for the "map_this" part of the URL, and only invoke the RewriteMap (and the script) for URLs where "map_this" is the top-level directory. Of course, you can change "map_this" to any string you prefer, as long as it is unique.
Jim