homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod rewrite and query strings
How to catch the query string to tack on the end.

Msg#: 212 posted 1:45 pm on May 21, 2003 (gmt 0)

I was with the (apparently incorrect) understanding that the following would catch any query string and stick in on the end of the rewritten URL.

RewriteRule ^(.*)-file\.html$ realone.php?key=$1&{query_string}

So that


would rewrite to


Is the only way to use the rewriteCond to capture the query string first and then have at least two rewrites for the same url (one with a query string, one without)?




WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 212 posted 4:34 pm on May 21, 2003 (gmt 0)


Try this instead:

RewriteRule ^([^-]*)-file\.html$ realone.php?key=$1?%{QUERY_STRING}

Query strings start with "?" and server variables in mod_rewrite are all caps and start with "%{"

Ref: Introduction to mod_rewrite [webmasterworld.com]



Msg#: 212 posted 5:11 pm on May 21, 2003 (gmt 0)

That worked, thanks. I think I may have missed the % in the beginning. I've read a bunch of different mod_rewrite tutorials and docs, but this particular technique is not very often mentioned.

There was already a? at the beginning of the querystring before the first parameter (key=$1) which is why I had the & before %{QUERY_STRING}.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved