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 have a bunch of domains that I want to go to one domain but various parts of that domain.

# this is what I currently have
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*\.?foo\.com$ [NC]
RewriteRule ^.*$ ${} [L,R=301]

# rewrite map file

The problem is that I don't want to have to have each domain be part of the RewriteCond. I tried

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

but that will do it for EVERY domain. I only want the domains that are in the mappings file to redirect, and then continue on to other rewrites if it doesn't match any domains in the mappings file.

share|improve this question

You can deref the map in a condition and make sure it's non-empty, and then capture it so you aren't going back to the map twice:

RewriteCond ${domainmappings:%{HTTP_HOST}) (.+) RewriteRule .* %1 [L,R=301]

share|improve this answer

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.