.htaccess canonical 301 redirects

I have noticed and lot of people asking for help with canonical urls, canonical 301s and .htaccess redirects in general. So I thought I would make a lovely thread for us all to point people to that need this information

First of all before editing your .htaccess file you should always take a copy of your current one in case something goes wrong.

1. The above should only be used once in a .htaccess file and always be before your reidrect code as above examples
2. .htaccess will not work on windows, its only for linux.
3. upload .htaccess files in ascii mode, sending it up as binary will break it.
4. Be sure to check for a current .htaccess file, as "." files are hidden so check your settings to make sure you can see them.
5. Remember to change domain.com to your domain!
6. Last of all, always check your changes to make sure its working correctly.

There are other ways of doing 301 reidrects so if you cant use .htaccess have a search on here and google and Im sure you will find what you need, if not simple ask

Also if I have missed any more out that people would like adding just let me know via PM so we can keep the thread clean, or simple add it yourself but be sure its right and that you dont post whats already here

Also if I have missed any more out that people would like adding just let me know via PM so we can keep the thread clean, or simple add it yourself but be sure its right and that you dont post whats already here

Here i found some useful .htaccess code for redirection methods. Thanks for sharing. It will be helpful for SEO newbies like me. Once again thank u..

Ok so I have been working on a standard .htaccess file which I can simple slap on all my new sites and client sites without having to make any changes or remember whats doing what! And here it is for all to enjoy

Hi,
We want to setup a 301 redirect from non www. to www.
If I do this will it affect the https urls?

Cheers
LDM

I should redirect the non-www to the www for both http and https (if not duplicate the code and make one copy use http and the second copy use https), but if you want to redirect http to https, then no you have to use the following to redirect: