Forum Moderators: phranque
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{QUERY_STRING} ^contact=(.*)
RewriteRule ^.*$ /misc/contact.php?contact=%1 [L]
My question is this: Technically, I think the address requested should be www.mysite.com/?contact=fred (note the slash). Does it matter if I create links that don't include that slash?
It works fine without the slash in the two browsers I've tried, but I don't want to cause any unnecessary hiccups.
Thanks in advance,
Prem.
Jim
You can re-code that to make it smaller/faster:
RewriteCond %{QUERY_STRING} ^contact=(.*)
RewriteRule ^$ /misc/contact.php?contact=%1 [L]
Jim
Should this code work (it doesn't seem to)? It should match any request for www.mysite.com/contact where the query string is not "contact=..."
It should internally rewrite www.mysite.com/contact?fred to www.mysite.com/misc/contact.php?contact=fred
RewriteCond %{QUERY_STRING}!^contact=(.*) [NC]
RewriteRule ^contact$ /misc/contact.php?contact=%1 [L]
Alternatively, I could put:
RewriteCond %{QUERY_STRING}!^contact=
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^contact$ /misc/contact.php?contact=%1 [L]
Prem.
I am trying to capture the query string as a back-reference, but it doesn't seem to work when I am matching for a negative result (i.e. the "!" at the front of the RewriteCond).
No, it won't work. You cannot use the contents of a negative match to create a back-reference. This is documented in the mod_rewrite documentation.
Alternatively, I could put:RewriteCond %{QUERY_STRING} !^contact=
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^contact$ /misc/contact.php?contact=%1 [L]
That should work. There's no need for the [NC] flag on the second RewriteCond, though, since ".*" matches anything.
Jim