Forum Moderators: phranque

Message Too Old, No Replies

.htaccess and mod rewrite again

Check inside, it's kind of hard to explain

         

Kaerigan

4:28 pm on Mar 29, 2007 (gmt 0)

10+ Year Member



Hello, this is my second time here. This time it's not actually not a problem - more like a thought.

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!

jdMorgan

11:10 pm on Mar 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simple answer: No, there's no simple way to do it.

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

Kaerigan

6:23 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



Ok, I see...

I found something that kind of did what I wanted. This is actually taken from CakePHP, since I was wondering how they did their pretty urls, and here's the answer:

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Then, I guess the URL gets chopped up and stuff happens.