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 web server. Lots and lots of DNS entries for domains and subdomains are pointing at this server. Most of them, like,, and, I want to keep. However, there is a certain list of subdomains for which I want to redirect.

For example, all of these urls resolve to the web server. is fine, we don't have to do anything, but bar and baz are on the list. That means we have to redirect them to

I can't just do a subdomain wild-card rewrite here because there is a long list of subdomains we want to redirect and a long list of ones we do not want to redirect.

Can/should I do a mod_rewrite that compares the subdomain to a list in a text file? If so, how do I do that? If not, how do I handle these redirects?

I know that I can make an entry into a mod_rewrite configuration, one for each subdomain, but that is a lot of typing, and there must be a better answer.

share|improve this question
up vote 4 down vote accepted

You could use the RewriteMap directive to provide a list of subdomains (or other keys) that you can use inside rewrite rules.

share|improve this answer
I agree... I've used RewriteMaps and they work extremely well. One thing I would be sure to do is to convert the text file once it's working to a berkley db file using the httxt2dbm utility – goose Aug 19 '09 at 16:58
I know about ReWriteMap, but it doesn't seem to do what I'm looking for. If it does, please provide an example. – Apreche Aug 19 '09 at 19:19
Take a spin through the examples: and then come back with questions? – CK. Aug 19 '09 at 21:31
Take a look at the section "Mass Virtual Hosting". I'm trying in my own server, if my tests are sucessful I will let you know. – HD. Aug 20 '09 at 1:48
Ok, I was wrong. rewritemap can do what I want. Just all the examples of it I saw were using it in another way. – Apreche Aug 20 '09 at 14:10

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.