mod_rewrite regular expressions

This is a discussion on mod_rewrite regular expressions within the Apache Web Server forums, part of the Web Server and Related Forums category; RewriteCond %{HTTP_HOST} ^([^\.w{3}]+)\.voosu\.com$ [NC] RewriteRule ^.*$ http://www.example.com/user.php?id=%1 [P,L] Here's ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2007
Joe.Lavers@gmail.com
 
Posts: n/a
Default mod_rewrite regular expressions

RewriteCond %{HTTP_HOST} ^([^\.w{3}]+)\.voosu\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/user.php?id=%1 [P,L]

Here's what I'm trying to do:

anyusername.example.com --> www.example.com/user.php?id=anyusername

Everything works fine, except one thing.

Before I redirect I want it to check for any mention of "www" (so that
there's no continuous loop) and maybe a few other terms in the
subdomain (let's say "private" for the sake of discussion) that I don't
want people to register as usernames. So this means www.example.com and
private.example.com wouldn't get used in this RewriteRule.

The problem is w{3} rejects a subdomain that has even just one "w" in
it. This means no one on my site can have a "w" in their name, which is
bad. What do I do to fix this?

Second, I don't even know how to include "private" or any other term i
want excluded into the regular expression.

Can somebody help me? I've tried googling this and looking up the most
obscure and complicated web sites but I can't find anything easy to
understand.

Thanks!

  #2 (permalink)  
Old 01-18-2007
HansH
 
Posts: n/a
Default Re: mod_rewrite regular expressions

<Joe.Lavers@gmail.com> schreef in bericht
news:1169062179.825605.233800@a75g2000cwd.googlegr oups.com...
> RewriteCond %{HTTP_HOST} ^([^\.w{3}]+)\.voosu\.com$ [NC]
> RewriteRule ^.*$ http://www.example.com/user.php?id=%1 [P,L]


IIRC a negated class -[^..]- takes all characters literal and thus makes the
quantifier -{...}- useless. Some versions allow
^([^\.(w{3})]+)\.example\.com.

Feel free to test this thought
RewriteCond %{HTTP_HOST} !^(www|private)\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/user.php?id=%1 [P,L]

P ... do you realy want to proxy, consider remapping

HansH


  #3 (permalink)  
Old 01-18-2007
Joe.Lavers@gmail.com
 
Posts: n/a
Default Re: mod_rewrite regular expressions

Thanks I'll try it right away!

> P ... do you realy want to proxy, consider remapping


What's the difference and how would I do this?

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:37 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0