Forum Moderators: phranque

Message Too Old, No Replies

rewriterule syntax help please

         

orion846

3:08 pm on Feb 28, 2008 (gmt 0)

10+ Year Member



hey guys,

i'm doing my best to figure out the syntax for the rewrite rule i need, but i can't figure it out.

my aim is to rewrite the following:

www.domain.com/s?i=whatever

TO

www.domain.com/show.php?i=whatever

the closest i think i've gotten is the following: rewriterule ^/s?i=(.*)$ /show.php?id=$1

but it won't work, i feel like maybe the ? in the first parameter isn't doing what i want it to, given that ? is a character that means something for the rewrite

jdMorgan

5:48 pm on Feb 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot examine the query string with RewriteRule, since it's not part of the URL, but rather a data string attached to the URL to be passed to the resource (script) at that URL. You must use RewriteCond:

RewriteCond %{QUERY_STRING} ^i=([^&]*)
RewriteRule ^/s$ /show.php?id=%1 [L]

If this code is for use in .htaccess, delete the leading slash from the RewriteRule pattern.

The code, as shown, allows only for a query string starting with "i=<something>" or "i=<blank>" but will not include any trailing parameters -- The match stops if any ampersand is found after the "i=" value.

For more information, see the Apache mod_rewrite documentation [httpd.apache.org].

Jim