Benmcfc Posted April 11, 2009 Share Posted April 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 11, 2009 Share Posted April 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-807265 Share on other sites More sharing options...
Benmcfc Posted April 11, 2009 Author Share Posted April 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-807278 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 11, 2009 Share Posted April 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-807292 Share on other sites More sharing options...
Benmcfc Posted April 11, 2009 Author Share Posted April 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-807327 Share on other sites More sharing options...
Daniel0 Posted April 12, 2009 Share Posted April 12, 2009 Try this (in .htaccess or httpd.conf): RewriteEngine on RewriteCond %{QUERY_STRING} ^n=([a-zA-Z0-9-]+) RewriteRule products\.php$ /products/%1 [R=301,L] RewriteRule products\.php$ /products/ [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-807782 Share on other sites More sharing options...
coalgames Posted April 26, 2009 Share Posted April 26, 2009 Just be patient and everything will be fixed. Google wants to help their users by providing quality content like yours. All you have to do is to just redirect the old pages and change the linking scheme. Quote Link to comment https://forums.phpfreaks.com/topic/153627-update-urls-in-google/#findComment-819875 Share on other sites More sharing options...
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.