I have just now upgraded one of my static website to a codeIgniter enabled website. I need to redirect the exact domain names of the old website to the new ones to avoid the 404 error.
- Old pages >
http://example.com/pagename.php
- New pages >
http://example.com/index.php/home/category_images/9(cat_id)
I do not a very high no. of pages so hard coding all the pages directly will not be a problem. I have tried :
RewriteEngine On
RewriteBase /
RewriteRule ^http://www.example.com/pagename.php$ http://example.com/index.php/home/category_images/9 [L,R=301]
Not working, I have no idea why. mod_rewrite
is enable on my apache server.
Also, just for the confirmation please also tell me in which folder I should put this file, I am confused between root dir or Application folder.
Thank you.
Version 2 : Now after suggestion from Mr. Michael, I tried to implement it using the redirect function like this :
Default Controller function : home.php
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->model('common_model');
$this->handle_redirects();
}
function handle_redirects ()
{
$redirects = Array(
'gorgeous-girls.php' => 'home/category_images/9'
);
$uri = implode('/', $this->uri->segments);
foreach ($redirects as $from => $to)
{
$from = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $from));
if (preg_match("#^{$from}$#i", $uri))
{
if (strpos($to, '$') !== false and strpos($from, '(') !== false)
$to = preg_replace("#^{$from}$#i", $to, $uri);
redirect($to , 'location', 301);
}
}
}
And my .htaccess looks like :
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
PS : I have removed index.php from my domain name structure. It looks like : www.example.com/controller/function/uri/uri
Now I am not getting an error page from my host, but I am getting an error page from the CodeIgniter.
Please help.