views:

46

answers:

3
+1  Q: 

Htaccess Redirect

I am looking to make www.purchase.example.com redirect to purchase.example.com, below is an example of what I am trying to do:

RewriteCond %{HTTP_HOST} ^www\.purchase\.
RewriteRule (.*) http://purchase.DOMAIN_NAME/$1 [L,R]

I need a variable that will replace DOMAIN_NAME with simply purchase.example.com.

Obviously I can hard code the purchase.example.com but I will need the code to work on multiple sites. Any suggestions?

A: 

For your knowledge:

I used a RewriteCond backreference:

RewriteCond %{HTTP_HOST} ^www\.purchase\.(.*)
RewriteRule (.*) http://purchase.%1/$1 [L,R]
Lizard
A: 

I would not do this in code, I would do this on the web hosting account.

Tony Borf
A: 

If you need it a little more generic redirect for every domain starting with www.:

RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule ^ http://%0%{REQUEST_URI} [L,R=301]
Gumbo