[eluser]LiorBroshi[/eluser]
I want to give my user's the ability to manage their own routes without saving the values to the database, therefore, I've created a screen which allows the users to manage their own routing. (image attached)
This is saved to a file under third_party/ directory and then merged into the main $route array with the code inside my routes.php file:
Code:
$route['default_controller'] = "welcome";
$route['404_override'] = '';
/*
|--------------------------------------------------------------------------
| Hard Coded Routes
|--------------------------------------------------------------------------
*/
# Internal / Hard coded routes come here
/*
|--------------------------------------------------------------------------
| Custom & Dynamic Routes
|--------------------------------------------------------------------------
*/
require_once( APPPATH . 'third_party/custom_routes.php' );
if ( isset($custom_routes) && is_array($custom_routes) )
{
$route = array_merge($custom_routes, $route);
# Check for a custom 301 route
$current_uri_request = ltrim($_SERVER['REQUEST_URI'],'/');
if ( array_key_exists($current_uri_request,$custom_routes) )
{
# Is this routing is an external one?
if
(
strpos($custom_routes[$current_uri_request],'http://') !== FALSE OR
strpos($custom_routes[$current_uri_request],'www.') !== FALSE
)
{
# Make sure we have a http:// prefix
if ( strpos($custom_routes[$current_uri_request],'http://') == FALSE )
{
$custom_routes[$current_uri_request] = 'http://' . $custom_routes[$current_uri_request];
}
header("Location: $custom_routes[$current_uri_request]");
}
}
}
This small workaround should enable 2 features which (AFAIK) does not exists in CI:
1. Allow easy management of $route values for a non-programmer user in the project.
2. Allow routing of website urls to external sources, not only internal controllers or places inside the same project.
The problem is that when executing the `header` function, it shows a CI 404 page which I cannot understand why! any ideas?