Catch all virtualhost with 301 redirect in apache

I you want to make sure all traffic only uses your preferred domain namn you can create a catch all virtual host in apache and redirect to the virtual host with the preferred domain name.

On your apache node select config and edit the httpd.conf file. Replace the current <VirtualHost ... section with the following and replace mydomain.com with your domain name.

<VirtualHost *:80>
 DocumentRoot /var/www/webroot/ROOT
 ServerName mydomain.com
 ErrorLog logs/mydomain-error_log
 CustomLog logs/mydomain-access_log common
</VirtualHost>

<VirtualHost *:80>
 ServerName www.mydomain.com
 ServerAlias *
 Redirect 301 / http://mydomain.com/
 ErrorLog logs/redirect-error_log
 CustomLog logs/redirect-access_log common
</VirtualHost>

 In this example all traffic that is not http://mydomain.com will be redirected to that domain.

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.