Htaccess rewrites and ampersands in URLs

This is new territory for me, sorry if this is wacky. I’ve been studying this thread on the topic and have working version locally. I’ve got the urldecode() working too.

Where I’m struggling is what to do if my URL isn’t as orderly as some&data, where there’s just 2 words with an ampersand.
RewriteRule ^tests/(.)\&(.)$ test.php?test_var=$1\%2526$2

I’m trying to figure out what I’d use for say 3 or more, not that this will happen, but I’m curious. What if I have something like /test/you&me&them?
RewriteRule ^tests/(.*) ./test.php?test_var=$1
on /test/you&me&them
echo’s :: hello test: you

Do I get this right? … I think I see how the regex finds ‘all’ then an escaped ampersand then ‘all’ again. then the Destination puts an ampersand between the 2 destination variables. Is there a way to create ‘n’ number or search groups with an ampersand between and ‘n’ number of destination variables?

Any guidance or insight would be appreciated. Does it make sense what I’m trying to get at?


The best guidance I can give you is to read the techo-geek treatise on URI Syntax by Tim Berners Lee: Uniform Resource Identifiers (URI): Generic Syntax where you will learn what characters are allow, which are allowed under certain circumstances and which are prohibited.



Thanks for the link David! I was hoping the USPS was going to put Tim Berners Lee on stamp, when they lifted the “you need to be dead to be on a stamp requirement”. :wink:

Now I think it’s unlikely that I’ll need a clean url with multiple ampersands. That’s just silly… especially if I’m in control of the names to some extent. I’ve got a nice working setup with the .htaccess file as it is now. I’m using PHP to clean up the variable and use it in the page titles and to connect to the db, so far things are working nicely… sofar :slight_smile: I’ve got a new question that relates to .htaccess files and a local Mac testing environment, but I think I should start a new thread.

The jist is I’m using a vhost file for my local testing, but then I’d like to be able to hit that domain from other machines, iPhone or iPad from within my local network. So, where I’ve got a site on my local development at: dev.mysite.loc/projects/dave I’d like to be able to hit that same site (directory) from within the local network at say:

I’ve learned that I can add the domain to the hosts file on other computers and use the same domain, but is there something I can do for something like an iPad or other device where I can’t get at a hosts file.

I’m going to do some research too. The goal is to be able to test my rewrites on other devices within my local network.

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^projects/(\\d+)*$ ./project.php?project_id=$1
RewriteRule ^projects/(\\d+)*/$ ./project.php?project_id=$1

RewriteRule ^projects/([A-Za-z0-9_-]+)*$ ./project.php?project_name=$1
RewriteRule ^projects/([A-Za-z0-9_-]+)*/$ ./project.php?project_name=$1

# weird ones
RewriteRule ^projects/(.*)\\&(.*)$ project?project_name=$1\\%2526$2
RewriteRule ^projects/(.*)\\&(.*)/$ project?project_name=$1\\%2526$2

RewriteRule ^projects/(.*)\\+(.*)$ project?project_name=$1\\%252B$2
RewriteRule ^projects/(.*)\\+(.*)/$ project?project_name=$1\\%252B$2


You’ll need to amend your httpd-vhosts.conf and hosts file on the “server,” too, to add the 10.whatever IP address. As far as your iWhatnot devices, perhaps using the server’s IP address will do the trick for you? At least it’ll get you close.