smart 404 page

Permalink
A little thought which hopefully starts a discussion and results in a new package/addon.

There's an old site which you would like to convert to c5. URIs look like this:
http://www.mysite.ch/contact.html...

Google might have found this site and directly links to it. After the conversion to c5 this will go to 404 which can be annoying, especially for big sites with logs of customers.

I thought it would be nice to have a little table in the dashboard with basically two columns: Old site, new site.

I tested this with a site event and it seems to work so far:

config/site_events.php:
<?php
Events::extend('on_before_render', 
'RedirectOldUrls', 
'checkUrl', 
'helpers/redirect_old_urls.php');
?>


helpers/redirect_old_urls.php
<?php
class RedirectOldUrls
{
   function checkUrl($page)
   {
      $urlMappings = array(
         '/foobar' => 'http://www.google.com'
      );
      $collectionPath = $page->c->getCollectionPath();
      if ($collectionPath == '/page_not_found')
      {
         $pathInfo = $_SERVER['PATH_INFO'];
         if (array_key_exists($pathInfo,$urlMappings)) {
            $newUrl = $urlMappings[$pathInfo];
            header("HTTP/1.1 301 Moved Permanently" );


When you enable the events and try to open /foobar, you'll be forwarded to google..

I'm not sure if using PATH_INFO is the best way to check the old address, I'm also not sure if it's smart to check for /page_not_found but I couldn't find a better way..

I didn't not put a lot of effort into this, I'm sure there's a better way but I just wanted to post this to share my thoughts..

Remo
 
AlbertPotato replied on at Permalink Reply
AlbertPotato
I agree that this would be helpful for a site conversion. I've only done c5 projects as new sites to date. Perhaps if I land a redesign or redev into c5 I'll give this a shot.
myFullFlavour replied on at Permalink Reply
myFullFlavour
I'd second this - we seem to be converting a lot of existing sites to Concrete5 right now..