Jump to content

canonicalization


wright67uk

Recommended Posts

Im having trouble with my site listing in google.

I have every page of my site listed in google but only for

i-stevenage.co.uk

I want google to list

www.i-stevenage.co.uk instead.

I believe this is called canonicalization!?!

 

If i were to put the below code into my site pages, would it do the job?

if yes, then where would I place it?

 

would it have to be the first line of my code?

 

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']);

}

 

and for my index page...

 

if ($_SERVER['REQUEST_URI'] == '/index.php')

{

  header( 'HTTP/1.1 301 Moved Permanently' );

  header( 'Location: http://www.i-stevenage.co.uk/' );

}

Link to comment
Share on other sites

Honestly, and this is just my opinion, I would not even care about the www. It is just 4 extra items people have to type and there is no benefit to having www. I made that mistake with my site and I wish I never did the www.

 

Just my two cents.

 

Instead of doing that in PHP, use a .htaccess, this will require mod_rewrite to be enabled:

 

RewriteEngine On

RewriteCond %{HTTP_HOST} ^i-stevenage.co.uk
RewriteRule ^(.*)$ http://www.i-stevenage.co.uk/$1 [R=permanent,L]

 

That should get you where you want to be without having to mess with the PHP side of it.

Link to comment
Share on other sites

What mistake did you make?

 

Im not so concerned about what the user types in, I just want all of my visitors, links, google ranking to go to

www.i-stevenage.co.uk opposed to i-stevenage.co.uk,

but yes I see what your saying on the user side of things.

 

Im not sure if mod_rewrite is enabled as godaddy only allow access to it via linux hosted sites and im windows hosted.

 

I havent put the if server script on my site yet, and now im curious of what effects it had on your site!?!

Link to comment
Share on other sites

www. is not any seo friendlier, just an FYI :) I do not think it makes much difference, other than your URL will always be 4 characters shorter no matter what.

 

If you want to test it and do not know if you have mod_rewrite enabled you can wrap it in an if statement:

 

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^i-stevenage.co.uk
RewriteRule ^(.*)$ http://www.i-stevenage.co.uk/$1 [R=permanent,L]
</IfModule>

 

This way your site won't break if mod_rewrite is not on. To test if it is working, you just have to goto the non-www version of your site and it should 301 redirect you to the www. version.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.