Apache: redirect from one subdomain to another

If you want to redirect from one subdomain to another (or from one virtual host to another) and have access to http.conf (or /etc/apache/sites-enabled) file(s), then simply do the following:

<VirtualHost *:80>
  ServerName old.mydomain.com
  RedirectPermanent / http://new.mydomain.com/
</VirtualHost>

Hint: to redirect all your requests from http://mydomain.com to http://www.mydomain.com, use the following:

<VirtualHost *:80>
  ServerName mydomain.com
  RedirectPermanent / http://www.mydomain.com/
</VirtualHost>

(do not forget trailing slash!)

Restart apache (sudo /etc/init.d/apache2 restart) and try it!

[misc]

In apache doc, they say that <VirtualHost> directives requires at least two components: ServerName and DocumentRoot. Well it seems DocumentRoot can be replace by Redirect directive.

[sources]

  • http://www.webmasterworld.com/forum92/2992.htm#1495863

Post a Comment

Your email is never published nor shared. You're allow to say what you want...