Linux : Redirection with Apache Web server

By | November 27, 2015

Here is a two different redirection type you can do with Apache. There is quite a few more method possibles such as with rewrite rules as well which will be covered later.

Redirect request made to a specific domain to a strict URL or domain.

This will basically send the requests as is to the destination domain RootDirectory. If you are redirecting to a domain rather than a specific URL, make sure to not forget the tailing slash RedirectPermanent statement.

<VirtualHost *>
ServerName domain.tld
ServerAlias optional.domain.tld
RedirectPermanent / http://new.domain.tld/
</VirtualHost>

Redirect everything, all possible requests from an old site to a new one (or one site to another if you prefer).

Let’s say we have the current site “domain.tld” and we have a new site named “new.domain.tld”, the following will basically redirect “http://domain.tld/anything” to the index page of “http://new.domain.tld/”.

<VirtualHost *>
ServerName domain.tld
ServerAlias optional.domain.tld
RedirectMatch 301 ".*" http://new.domain.tld/
</VirtualHost>