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 know you can redirect a specific subdomain to another domain and I need something but less specific. I need some way of redirecting every subdomain to another domain and Im not sure if this is actually possible. I was wanting to do this directly inside the apache config fileinstead of with htaccess. I am using debain6.

Any suggestions would be much appreciated.

share|improve this question
    
See this also You need set up DNS record for wildcard subdomain. *.subdomain.tld. IN A 1.2.3.4 –  Guntis Apr 18 '13 at 8:49
add comment

1 Answer

To redirect all sub domains to another domain:

<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *.domain.com
    Redirect 301 / http://targetsite.com/
</VirtualHost>

You could also simply create a wildcard alias for the target domain. The advantage of this is that it would allow you to serve cookies from the requested domain. This will not change the address bar in the browser like the first example.

<VirtualHost *:80>
    ServerName targetsite.com
    ServerAlias *.domain.com
    DocumentRoot /var/www/targetsite.com
</VirtualHost>
share|improve this answer
1  
A 302 redirect is better, unpicking a 301 if you want to use a previously redirected subdomain is really a pain. –  Iain Apr 18 '13 at 9:12
add comment

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.