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.
www to non-www 301 redirect:
non-www to www 301 redirect:Code:Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} !^domain\.com$ RewriteRule (.*) http://domain.com/$1 [R=301,L]
index.php to domain.com/ redirect (change extension as needed):Code:Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.domain\.com$ RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
301 reidrect old page (change extension as needed):Code:Options +FollowSymLinks RewriteEngine on # index.php to / RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/ RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
Change file extension (change extension as needed):Code:Redirect 301 /old-page.html http://www.domain.com/page.php
A couple of bits to remember:Code:RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php
1. The above should only be used once in a .htaccess file and always be before your reidrect code as above examplesCode:Options +FollowSymLinks RewriteEngine on
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![]()





Comments on this post