Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod rewrite and query strings

How to catch the query string to tack on the end.

1:45 pm on May 21, 2003 (gmt 0)

Junior Member

joined:Apr 27, 2003
votes: 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)?


4:34 pm on May 21, 2003 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
votes: 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]


5:11 pm on May 21, 2003 (gmt 0)

Junior Member

joined:Apr 27, 2003
votes: 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}.