[eluser]Phil Sturgeon[/eluser]
Ok I had this one dirty way of doing something similar before. Basically if it got a 404 (meaning no controllers exist) it would then do a cheeky check in the db for it, all done through a controller.
Make a file libraries/MY_Exceptions.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions
{
function show_404($page = '')
{
global $CFG;
// Removes the name of the script from the request uri, so we can grab segment1
$uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']);
$segments = explode('/', $uri_string);
// Send em to check the page only if it exists
$check = (isset($semgents[1])) ? '/check/'.urlencode($segments[1]) : '';
// Redirect to a CI controller where we have more API access
header('Location: '.$CFG->item('base_url').'index.php/page_missing'.$check);
/*
log_message('error', '404 Page Not Found --> '.$page);
echo $this->show_error($heading, $message, 'error_404', $title);
exit;
*/
}
}
?>
Then in the page_missing controller, I had one function that would run a check and see if the segment was in the database as a group title (for you it would be user name). Then if its not, it passes it to the default part of page_missing which is just a 404 error. With this code you can customise your 404's alot better than the normal ones too, so it has two benefits.
This is an example of my 404 controller.
Code:
<?php
class Page_missing extends Controller {
function index()
{
$this->load->load('404');
}
// All 404's come through here, we check there is no user with the name
function check($possible_match = '')
{
// Send straight to normal page missing
if(empty($possible_match)):
redirect('page_missing');
endif;
$this->load->model('user_model');
// Its a user!
if($user = $this->user_model->getByUsername($short_name)
// Go to the normal page missing page
else:
redirect('page_missing');
endif;
}
}
?>