homepage Welcome to WebmasterWorld Guest from
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

Rewrite URLs with if statements?
more confusing regex than you can shake a stick at.

 11:53 am on Apr 8, 2004 (gmt 0)

I'll try and be as general as I can here for simplicity's sake.

I have a file called file.php which can contain up to six variables in the query string (a=1&b=2&c=3 etc). I've rewritten the href URLs to the two most important variables, and then the four others in a query string, so a typical URL would look like host.com/a1/b2.htm while with the query string (less common occurances) it would be host.com/a1/b2.htm?c=3&d=4 etc.

I then have the following rewrite rule:

RewriteRule ^a([0-9]*)/b([0-9]*).htm (points to) file.php?a=$1&b=$2

which matches the two variables, but if the href URL has extra vars, they don't get included, because they don't redirect correctly to file.php

So is it possible to have a sort of 'if' statement in the rewrite rule, or will I need a new rule entirely? My thought is that if I can say: if there's a question mark after the .htm, then append its trailing contents to the file.php string in the form of &vars. I get the impression that something like (?(?[a-z]*)) would work, but I'm not very good with regular expression (if only they were human readable! :p)

Does this make sense?




 3:48 pm on Apr 8, 2004 (gmt 0)


See the RewriteCond [httpd.apache.org] directive, and the [QSA] (query string append) flag of RuleRewriteRule [httpd.apache.org].



 4:13 pm on Apr 8, 2004 (gmt 0)

I shall have a goosey gander, cheers. So much documentation for what basically comes down to a few characters :\
If it weren't for the perverse satisfaction of rewriting pretty URLs and condensing script, I'm sure I wouldn't bother :)


 7:56 am on Apr 9, 2004 (gmt 0)

Ah, but mod_rewrite and the regular expressions that it uses pack a lot of power into those few characters! :)


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