MrAdam Posted October 7, 2008 Share Posted October 7, 2008 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 More sharing options...
justsomeguy Posted October 7, 2008 Share Posted October 7, 2008 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 More sharing options...
Jamesking56 Posted October 7, 2008 Share Posted October 7, 2008 No problem, but my name's not Adam.LOL! He meant is was from him, like saying:thanks for your help,JamesOK? LOL! Link to comment Share on other sites More sharing options...
justsomeguy Posted October 7, 2008 Share Posted October 7, 2008 Thanks for clearing that up. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 8, 2008 Share Posted October 8, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.