According to the seo
of the world, it is good practice to force your website to always use
the same domain. So, instead of having your site work at both
www.example.com and example.com, choose one. Once you’ve chosen which
form of your site to use, it’s time to setup 301 redirects to enforce
If you’re using Apache, it’s very easy, just add a quick mod_rewrite
rule. You can remove the
or force the use of
But since IIS doesn’t use .htaccess files, it takes a little more
Create a php.ini with the following content and upload it to your site root
Keep in mind that you’ll need to change the file path to reflect the
setup of your server.
Upload canonical.php with the following contents
This method assumes that you don’t have access to modify the server
settings, ie: shared windows hosting. If you are able to modify how
IIS is setup I’m sure there’s a better way to do this.
When PHP is run as a cgi, you can overwrite the php.ini settings by
putting a php.ini in the site root. So if your windows host is not
running php as a cgi, this won’t work. I think that php is always
run as a cgi on IIS, but I could be wrong.
This will only work if the site is using PHP – if you have a
completely static site this won’t help you. In order to use this
with a static site, you’d have to change the server settings to
treat your html files as php files.