The canonical redirect

Meet the canonical redirect

The canonical redirect, or the 301 redirect will help you here. And it is not that hard to do, most servers will let you make an .htaccess file. So all you have to do is that when a client requests you redirect the to Easy peasy.

But how to do that?

Well, when you access your site through ssh and go to your webroot there is probably an .htaccess present because of Drupal, Wordpress, Joomla, or whatever CMS you are using. So you just add this to the top: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com RewriteRule ^(.*)$ [R=,L] </IfModule> This piece of code first check if you have the rewrite module installed. So if you don't have that is will just do nothing. Your redirects are not working, but at least you don't get an error. Then is switches on the RewriteEngine. And here are the two lines that do all the work.

  1. If the host does not start with
  2. Rewrite it to using a 301 redirect

And that's it. These 5 lines will make you all the difference.