website redirection using httpd.conf file

To redirect the website, you can do two ways one for .htaccess redirection which was very easy/handy and everybody can do because you don’t want any privilege but for apache (using httpd.conf file) redirection you should have super (sudo or root) privilege to do the change or else you must request the hoster to do it.

1) www to Non-www redirection

I have added two examples script here for www to Non-www redirection.

# Example - 1 #
<VirtualHost *:80>
ServerName www.2daygeek.com
Redirect 301 / https://2daygeek.com/
<VirtualHost> 

# Example - 2 #
<VirtualHost *:80>
ServerName www.2daygeek.com
Redirect permanent / https://2daygeek.com/
</VirtualHost>

2) Non-www to www redirection

I have added four examples script here for Non-www to www redirection.

# Example - 1 #
<VirtualHost *>
ServerName 2daygeek.com
Redirect 301 / https://www.2daygeek.com/
</VirtualHost>  

# Example - 2 #
<VirtualHost *:80>
ServerName 2daygeek.com
Redirect permanent / https://www.2daygeek.com/
</VirtualHost> 

# Example - 3 #
<VirtualHost *:80>
ServerName 2daygeek.com
RedirectMatch permanent ^/(.*) https://www.2daygeek.com/$1
</VirtualHost>

# Example - 4 #
<VirtualHost *>
ServerName 2daygeek.com
Redirect / https://www.2daygeek.com/
</VirtualHost>

Hope this article was useful for you. Kindly provide your valuable feedback/comments in the commenting section. Stay tuned with us !!

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *