Skip to main content

How to redirect 1 domain name to another and correct URL bar

If like me, you want to redirect your old domain name to your new one while correcting the visitors’ URL bar, the solution is quite simple in fact using your VirtualHost.

Here is my example, I wanted to redirect www.freelydifferent.com and freelydifferent.com (Without www) to directly freedif.org and make sure the domain name change in the visitors’ URL bar, you need to tweak a bit your Vhost located in your

/etc/apache2/site-enabled/my_website

to add the domain name you want to redirect at the beginning of your existing VirtualHost.

Here is the interesting part of mine:

 

 

First, the server will answer any request on the port 80, the default HTTP port (*:80) for the ServerName freelydifferent.com or the Alias www.freelydifferent.com and will redirect any folder called (/) to the website http://freedif.org/

Like that, if you call freelydifferent.com, it will redirect to freedif.org. Or if you call www.freelydifferent.com/plop, it will redirect to freedif.org/plop

Easy right?