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

I'm running Apache 2 on Ubuntu and would like to forward all request on one subdomain to another.

Example:

a.example.com/page.html would forward to b.example.com/page.html

I want to forward all requests (not just a few pages).

How would I set that up in my virtual hosts?

share|improve this question

2 Answers 2

up vote 1 down vote accepted
RewriteEngine on
RewriteCond %{HTTP_HOST} ^a\.example\.com
RewriteRule ^(.*)$ http://b.example.com/$1 
share|improve this answer
    
Where does that code go? –  Shpigford Mar 20 '10 at 4:14
    
Either in your <VirtualHost> section or in a .htaccess file, depending on how you have things set up. –  EEAA Mar 20 '10 at 5:18

I really wonder why everybody always tries to solve those redirect problems with mod_rewrite rather than mod_alias.

Put the following line inside the container of a.example.com:

RedirectPermanent / http://b.example.com/
share|improve this answer
    
That won't redirect a.example.com/test-page.html to b.example.com/test-page.html as requested by the OP. –  ceejayoz Mar 21 '10 at 1:31
    
Of course it will! Have you even tried it? –  joschi Mar 21 '10 at 6:32
    
@ceejayoz: wiki.apache.org/httpd/WhenNotToUseRewrite - if I could upvote joschi twice, I would. –  pjmorse Oct 8 '12 at 1:43

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.