homepage Welcome to WebmasterWorld Guest from 50.19.206.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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.
bonanza




msg:1500292
 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

domain.com/widget-file.html?a=1&b=2

would rewrite to

domain.com/realone.php?key=widget&a=1&b=2

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)?

thanks

 

jdMorgan




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

bonanza,

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]

HTH,
Jim

bonanza




msg:1500294
 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