Jump to content

Update URLs in Google?


Benmcfc

Recommended Posts

I've recently changed the links on a couple of my sites using .htaccess rewrite.

 

For example, before it would say:

/products.php?p=product-name

 

Now it appears as:

/products/product-name/

 

Is there a way to get Google to update their index to reflect the changes?

If it required removing the current indexed pages through Webmaster Tools and letting them respider would I lose all progress on the SEO front?

 

Thanks.

Link to comment
Share on other sites

You don't need Webmaster Tools for that.

 

Just redirect your old page with 301 code to the new one and wait. Google will crawl your website and find them.

 

In your products.php use something like that (don't forget to add some security check) :

 

<?php
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: http://www.yoursite.com/products/".$_GET['p']."/");
   header("Connection: close");
   exit();
?>

 

so each time someone come to see this url

http://yoursite.com/products.php?p=product-name

it will be redirect to :

http://www.yoursite.com/products/product-name/

in a SEO friendly way.

 

All links in others website to yours, bookmark and robots like google won't end up in a dead link.

 

You can handle the new page with a new php file :

 

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ prod.php?p=$1 [L]

 

 

prod.php will essentially be exactly as your old products.php

Link to comment
Share on other sites

Thanks for the reply.

 

Is that going to work if the 'new' URL is technically still pointing at the same location as the old one? Can I perhaps check whether the user has used the SEO friendly URL or the old one with an if statement? I would've thought the URL the script sees is the actual one rather than the rewritten one.

Link to comment
Share on other sites

It would work great. Simpler than my solution actually.

 

something like that in products.php

 

<?php

$uri = $_SERVER['REQUEST_URI'];
if (!$uri ...)   /* If the URL matches the old URL pattern redirect */
{
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: http://www.yoursite.com/products/".$_GET['p']."/");
   header("Connection: close");
   exit();
}

.....

?>

 

With all the sanitization and security check of course and be sure it work or you may end up in a infinite loop of redirect :)

Link to comment
Share on other sites

That's brilliant, it's all working fine.

 

Thanks for the help  :)

 

 

If anyone has found this page through Google and is struggling with the checking of the URL to redirect,

 

<?php
$uri = $_SERVER['REQUEST_URI'];
$pieces = split ("[.?=]",$uri);

if ($pieces[1] == 'php' ) { 
//headers as above
}
?>

 

$pieces[0] is /products

$pieces[1] is php

$pieces[2] is p

and $pieces[3] is the product type

 

If the user has reached the page through the new SEO friendly link, $pieces[1] != php so the headers aren't sent.

Link to comment
Share on other sites

  • 2 weeks later...
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.