Redirect multiple domains to the same website » serra.me

Redirect multiple domains to the same website

Over the last couple of years, I aquired a nice collection of various domains. Since I only keep them for historical purposes, I decided to redirect all domains to this blog domain. Usually, you can achieve such a redirection by simply pointing all your domains to the same virtual host within your webserver configuration in case you are using WordPress. However, this won’t work when using some caching plugins. Some .htaccess magic will help though.

The following .htaccess snippet redirects every domain that’s not called www.targetdomain.com to the – well – desired target domain:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.targetdomain.com
RewriteRule (.*) https://www.targetdomain.com/$1 [R=permanent,QSA,L]

The redirection also works for all queries – https://olddomain.com/foo will always redirect to https://www.targetdomain.com/foo.

Leave a Reply

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