PDA

View Full Version : Making the change to clean urls...



lonewolf
28 Feb 2007, 03:50 PM
... what do i do with the old ones?

I am currently rewriting my website, from the bottom up, and as part of this rewrite comes clean urls. How do I handle the 4000+ untidy urls in a way that google won't tell me to f. off?

http://domain.com/showpic.php?view=1&gallery=house&image=dscf0001&ext=jpg (what was I thinking?)

will now be similar to

http://domain.com/pictures/house/dscf0001

If I use 301 redirect in htaccess, will that slow the server down on every request, not to mention that I will have to hand code the new url.

Would it be better to have a 404 document which will scan the uri and redirect accordingly? (sill hand coded)

Can I get away with just redirecting showpic.php to /picutures which will show the galleries to be selected or will this confude google?

Any Ideas?

Thanks in advance

Tim

PS This is on a LAMP server.

lonewolf
28 Mar 2007, 09:31 AM
I've written a PHP script that functions perfectly for this. It is my 404 ErrorDocument so when a bad (old) url is entered this script processes it and redirects the user to the new page. As I said it works perfectly, but not for search engines! For some reason they are not picking up on the 301 Redirect, but the 404.

How do I stop ErrorDocument 404 from sending header 404, or how do I overwrite the header 404 with 301?


A bit more information:

If you were to go to the old url http://lonewolf-online.net/computer.php you are automatically redirected to http://lonewolf-online.net/computers fine, but google seems to be stopping at a 404 Not Found.

My redirect code looks like this: (I have already scripted the variables $page to extract from the request_uri)

switch($page)
{
case "index.php"; redirectURL('/'); break;
case "about.php"; redirectURL('/about'); break;
case "astro.php"; redirectURL('/astronomy'); break;
case "cars.php"; redirectURL('/cars'); break;
case "computer.php"; redirectURL('/computers'); break;
...
}

function redirectURL($newrl)
{
//Custom logging procedure here
//

//Finally redirect to new page
header("HTTP/1.1 301 Moved Permanently");
header("Location: $newrl");
}

I've done it this way because some of the old urls have upto 5 parameters which may or may not exist and the new urls require that each parameter is passed. For example my blog:

function redirectBlog($params)
{
$section = $params['section'];
if (!$section)
$section = "all";

$section = str_replace(" ", "_", $section);
$section = str_replace("%20", "_", $section);
$section = strtolower($section);

$blogitem = $params['blogitem'];

if ($blogitem != "")
{
$section = "permalink";
$blogitem = 'item' . $blogitem;
}

$start = $params['start'];
if (!$start)
$start = "0";

redirectURL('/blog/' . $section . '/' . $start . '/' . $blogitem);
}

I couldn't see how this would work in a .htaccess file.




Thanks in advance...

Tim