Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to make redirect to, 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

Obviously i can hard code the but i will need the code to work on multiple sites. Any suggestions?

share|improve this question
up vote 2 down vote accepted

You could use a RewriteCond backreference.

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


RewriteCond %{HTTP_HOST} ^www\.purchase\.(.*)
RewriteRule (.*) http://purchase.%1/$1

Which suprisingly similar to the one posted while I was posting.

share|improve this answer
I voted you up, but had to accept the first correct answer! cheers anyway! – icelizard Aug 3 '09 at 15:50
Sorry. Tough going ;) – Dan Carley Aug 3 '09 at 15:57
Consecutive answer ids too... :) – CK. Aug 3 '09 at 16:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.