Apache Server Canonical Redirect

Hi guys,

Need a little professional assistance… Canonical URLS

I have just been reading about this and assume that ‘every’ site should combat this, right?

Is there any risk of harming your existing page rank and SERPS?

We have stupidly been allowing people to link to us using:

http://www.domainname.com.au/store
http://www.domainname.com.au/store/

How can we find out where we stand on this in google results… If we are suffering?

I found 3 example codes for a htaccess solution but not sure which one to use. (we dont have any subdomains)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com.au$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com.au/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.tld$
RewriteRule (.*) http://www.yourdomain.tld/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com.au
RewriteRule (.*) http://www.yourdomain.com.au/$1 [R=301,L]

Please confirm that this will in no way degrade our rankings.

Thank you.

Thanks for the reply :slight_smile:

if you need to force the trailing slash

Do I need to?

Make sure you do some research or ask questions in the Apache forum to get the proper usage of the [L] qualifier so you don’t end up in infinite redirects.

Sorry, not sure what you mean

I can confirm it will NOT degrade your rankings (provided that your redirects are set-up correctly).

What this does in effect is consolidate all your backlinks that those variations have accumulated, so you should (depending on the number/nature of those backlinks) see a net benefit.

As for the .htaccess bit, i am NOT an expert in redirections and regex, but this should work fine:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]

if you need to force the trailing slash (you must check that doing this won’t break other parts of your site), then you can use the following .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [R=301]

Make sure you do some research or ask questions in the Apache forum to get the proper usage of the [L] qualifier so you don’t end up in infinite redirects.