-2

How to write a virtual host config in apache for, a particular domains is not present in the list we mentioned in the vhost configuration, automatically apache need to redirect to our mentioned website in the config..... For eg:(listed domains) xxx.com yyy.com zzz.com

Suppose someone have to register subdomain or domain with our server ip like aaa.com, after they trying to access the aaa.com, apache automatically redirects to our mentioned site in apache vhost config....

1 Answers1

0

You simply configure a vhost with the alternate server names which only does redirects :

<VirtualHost *:80>
    ServerName zzz.com
    ServerAlias zzz.net www.zzz.net zzz.org www.zzz.org ...
    Redirect / http://www.zzz.com/ permanent
</VirtualHost>

<VirtualHost *:80>
    ServerName www.zzz.com
    ... here comes specs for http://www.zzz.com/
</VirtualHost>

If anybody hits the alternate names (eg. http://zzz.com, without the www. prefix), its browser will be immediatly redirected to the 'canonical' one. Note that this redirect keeps the URL, hence http://zzz.com/foobar is redirected as http://www.zzz.com/foobar.

zerodeux
  • 656
  • 4
  • 6
  • Thanks for your reply, but my case is different,we have hosting multiple domain names for single ip using name-based virtual host,if the requested domain name does not match any of the configured domain names, apache need to redirect that site.How to write the rule for this case...... – user201078 Dec 02 '13 at 13:38
  • @user201078, are you looking for default apache page ? – Kumar Dec 02 '13 at 18:54
  • @user201078 : Actually I did answered to your exact problem but was not exactly clear about this. The first vhost will catch *any vhost* which is not defined elsewhere. You actually don't have to list a bunch of things in the ServerAlias stanza. – zerodeux Mar 04 '14 at 15:23