You are here:  » Canonical Issue

Support Forum



Canonical Issue

Submitted by noodles on Thu, 2007-01-04 10:21 in

Hi David,

My usual way round this is to put a mod_rewrite 301 in the .htaccess file but this seems to cause problems with PT, is it safe to put the following code in the /includes/common.php? it seems to work ok...

<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
    
header('HTTP/1.1 301 Moved Permanently');
    
header('Location: http://www.'.$_SERVER['HTTP_HOST']
    .
$_SERVER['REQUEST_URI']);
}
?>

Thanks
David

Submitted by support on Thu, 2007-01-04 10:54

Hi David,

Shouldn't be any problem with normal page views; but you may find an issue with the automation scripts (if you use them) as they include common.php but HTTP_HOST would not be set. If you do find that's a problem, you can always just add a check for whether HTTP_HOST contains anything before doing the test...

Cheers,
David.

Submitted by noodles on Thu, 2007-01-04 11:05

Ok thanks

Submitted by Oisin on Fri, 2007-01-05 06:21

hi,

in relation with canonical URLs.

i also noticed that the

www.example.com/merchant/merchantname

gives an error 404

how can we resolve this and point the

www.example.com/merchant/merchantname

to

www.example.com/merchant/merchantname/

thank you.

Submitted by support on Fri, 2007-01-05 09:37

Hi Oisin,

Although this does give 404, it should never be a problem because it is not a URL that any human is ever going to be typing in and is likely to get wrong. Secondly, because search engines will never see a link to the wrong version they will never index it.

However, if you want to add a rule to handle that situation, you need to use a 301 redirect in your .htaccess as follows:

RewriteRule ^merchant/(.*) merchant/$1/ [L,R=301]

This line must go AFTER the other merchant rules...

Cheers,
David.