views:

32

answers:

2

Hi! I need help with deciding how to redirect my old urls to the new ones. At this moment I have the urls like

myhost.com/viewrecipe.php?id=2

But I want them to look like

myhost.com/recipes/pear-pie

The problem is that the website is already indexed in Google. Is there any way to write a 301 redirect for search engines to redirect them from the old type of urls to the new one?

If it's impossible to achieve without using id in the new url type, what are other option to makethis transition as smooth as possible for search engine?

P.S. all those are dynamic urls

A: 

Have you tried an [R=301] after your rewrite rule ?

MatTheCat
A: 

You can use a .htaccess file in the root of your application containing:

redirect 301 viewrecipe.php?id=2 http://www.myhost.com/recipes/pear-pie

Yes this will be needed for all your URLs... if not you can't try to write a rewrite but you will neded the id on the new seo-friendly url.

Another way will be to be able to acces to viewrecipie.php?id=2 and code something like:

<?php
// get the new name dependeind of the id
$slug = Posts::getByID($id);

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.myhost.com/recipes/".$slug);
?>

And a shortest way:

header("Location: http://www.myhost.com/recipes/".$slug",TRUE,301);
Isern Palaus
Thank you, these were the only ways that came to my mind and you confirmed them :)
jusik