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.

100+
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} ^([^.]+).example.net [NC]
  2. RewriteCond %{HTTP_HOST} !^www.example.net [NC]
  3.  
  4. RewriteRule ^.*$ http://example.net/disp_page.php?a=%1 [NC,QSA,L] 
So this works fine with :

potatoes.example.net

that goes to example.net/disp_page.php?a=potatoes

and the page displays

BUT if I have

recipes.potatoes.example.net

then it doesn't work

It should go to : example.net/disp_page.php?a=recipes.potatoes

Which would work fine.

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

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


helimeef
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 ".example.net"
Mar 26 '12 #2

Post your reply

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