By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Simple regex problem - please help.

P: 290
Hi ,

My simple redirect is working EXCEPT if there is a period in the string.

This is what I have:

Expand|Select|Wrap|Line Numbers
  1. RewriteCond %{HTTP_HOST} ^([^.]+) [NC]
  2. RewriteCond %{HTTP_HOST} !^ [NC]
  4. RewriteRule ^.*$ [NC,QSA,L] 
So this works fine with :

that goes to

and the page displays

BUT if I have

then it doesn't work

It should go to :

Which would work fine.

Does any one know how I should adjust my code above so that it takes everything up to the ""?

Mar 5 '12 #1
Share this Question
Share on Google+
1 Reply

P: 77
Expand|Select|Wrap|Line Numbers
  1. RewriteCond %{HTTP_HOST} ^(.+)\.example\.net [NC]
Backslash your periods. They're special characters in regexes -- the reason that your code actually happens to work is because the period selects anything. This would have even matched www4exampleanet.
This new regex just selects everything before the string ""
Mar 26 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.