bode Posted January 30, 2009 Posted January 30, 2009 (edited) Hi, I'm trying to resolve a canonicalization issue with my site to improve serps in google. As you may be aware, these are the 4 variations that exist: http:// www.mysite. com/ http:// www.mysite .com/index.html http:// mysite .com/ http:// mysite .com/index.htm The internal links on my site point to the homepage as <a href="index.html" etc My back links from external websites point to http:// www. mysite .com/ In cpanel, I'm not sure if I have set up my 301 redirects correctly. My browser and various online redirect tools give different answers. How do I set up the 301 correctly? I'd like them to all point to www.mysite . com/ Thanks Edited January 30, 2009 by bode Quote
TCH-Bruce Posted January 30, 2009 Posted January 30, 2009 If you use this you should be set. Add it to the .htaccess file in the public_html folder. >Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] Replace domain . com with your domain name. Here's a quick little tool for doing this. Quote
bode Posted January 30, 2009 Author Posted January 30, 2009 Thanks, I've added the following code: >Options +FollowSymLinks RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/ RewriteRule ^(.*)index\.php$ /$1 [R=301,L] Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} ^natural-light-cambridge.co.uk [nc] RewriteRule ^(.*)$ http://www.natural-light-cambridge.co.uk/$1 [R=301,L] This appears to be different from the code using the cpanel 301 redirects. Quote
TCH-Bruce Posted January 31, 2009 Posted January 31, 2009 That top portion can be removed if you haven't already. What it does is replace index.html with index.php. Unless you are using that it can safely be removed. It would be if you were changing your site from using html to php pages. The one I gave is to just force www in front of any request for your domain. Quote
bode Posted January 31, 2009 Author Posted January 31, 2009 I had pasted the wrong code! Options +FollowSymLinks RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/ RewriteRule ^(.*)index\.html$ /$1 [R=301,L] Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} ^natural-light-cambridge.co.uk [nc] RewriteRule ^(.*)$ http://www.natural-light-cambridge.co.uk/$1 [R=301,L] If I understand your link, I'm hoping that this will redirect /index.html to the co.uk/ So will these two codes be suitable for these potential problems on our version of apache? domain.com domain.com/ www.domain.com domain.com/index.html www.domain.com/index.html to all point to www.domain.com/ Quote
TCH-Bruce Posted January 31, 2009 Posted January 31, 2009 All you need is what I entered in my first reply. All the other redirects can be removed. >Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^natural-light-cambridge.co.uk [nc] rewriterule ^(.*)$ http://www.natural-light-cambridge.co.uk/$1 [r=301,nc] The $1 will be replaced by what ever page they are accessing (ex. index.html, about.html, contact.html, etc...) every thing will appear with www.natural-light-cambridge.co.uk/ in front of it. Quote
bode Posted February 1, 2009 Author Posted February 1, 2009 Thanks for your time on this. I've removed the other redirects and I'm using the code which you have provided. However, (www....index.html is not redirecting to www....co.uk/ as it did before. Also when I click on a homepage link within an inner page on my site, the link arrives at www..../index.html Will this cause duplicate content on google? Quote
bode Posted February 2, 2009 Author Posted February 2, 2009 Found a new code which addresses all the potential canonicalization problems. Appears to be working fine. >Options +FollowSymlinks RewriteEngine on # RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.(s?html?|php[456])(\?[^\ ]*)?\ HTTP/ RewriteRule ^(([^/]+/)*)index\.(s?html?|php[456])$ http://www.mydomain.co.uk/$1 [R=301,L] # RewriteCond %{HTTP_HOST} !^(www\.mydomain\.co.uk)?$ RewriteRule (.*) http://www.mydomain.co.uk/$1 [R=301,L] Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.