Jump to content

Tricky mod_rewrite..


MrAdam

Recommended Posts

Hi all!Well I'm trying to setup mod_rewrite so that when a user accesses (this is just an example):(...).com/id/123/name/Adamit reconstructs the URL to:(...).com/?id=123&name=AdamThat on it's own I could do, however I want there to be an unlimited number of variables available... which obviouslly means I don't know what names they'll have or what values they'll have. Which is where I'm stuck. I don't know how to sort of 'loop' through them all?Does anybody have a quick answer or tip, or perhaps a link to a tutorial that might explain how to do this?Cheers for your help, Adam!

Link to comment
Share on other sites

I don't know of a rule to allow an infinite number of arguments, you would need a rule for each number of arguments you want to allow.RewriteRule ^(^[/]+)/(^[/]+)$ /?$1=$2RewriteRule ^(^[/]+)/(^[/]+)/(^[/]+)/(^[/]+)$ /?$1=$2&$3=$4RewriteRule ^(^[/]+)/(^[/]+)/(^[/]+)/(^[/]+)(^[/]+)/(^[/]+)$ /?$1=$2&$3=$4&$5=$6etc

Cheers for your help, Adam!
No problem, but my name's not Adam.
Link to comment
Share on other sites

This is untested...

<?php$words = explode('/', $_SERVER['REQUEST_URI']);for($i = 0; $i + 1 < count($words); $i += 2){	$variables[$words[$i]] = $words[$i + 1];}?>

Now you can access them like $_GET:

$variables['name']

If you need to do this with scripts that can't be accessed via your document root, you can cut $_SERVER['SCRIPT_NAME'] from the beginning of $_SERVER['REQUEST_URI'] and take the remainder of the latter.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...