Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a web server. Lots and lots of DNS entries for domains and subdomains are pointing at this server. Most of them, like www.foo.com, foo.com, and subdomain.foo.com, 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.

test.foo.com bar.foo.com baz.foo.com

test.foo.com 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

bar.list.foo.com baz.list.foo.com

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

1 Answer 1

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
1  
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: httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html and httpd.apache.org/docs/2.2/rewrite/rewrite_guide_advanced.html 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

 
discard

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.