how to create 301 redirect in codeigniter


how can i create a 301 redirect in codeigniter?
What i want to do is redirect the 301 and 404 pages to homepage(index.php)

[eluser]Hani A.[/eluser]
redirect('/article/13', 'location', 301);

Check out:

(At the very bottom of the page.)

thanks for the quick reply!

but, where should i put this code(redirect) and also i have so many url to redirect into 301..
how can i do this properly? can .htaccess do this and how?

May I ask why you want to redirect all such errors to your homepage? It can negatively affect search engine results as well as confuse your users.

I am rebuilding a site and primarily changing almost all of its page URL.

Anyway, What would be a better solution for this? Any inputs are much appreciated

I would recommend assigning as many appropriate redirects as you can, sending old URLs to their newer, current locations (via htaccess is best, IMO). I understand that it may be quite a bit of work depending on the amount of URLs you currently have, but that is the ideal solution.

If you have a set URL structure with some dynamic text that will remain the same, you can set up a broad redirect. For example, say you have a blog with a URL structure like If your new URL structure is something like, you can set up a catch-all redirect.

I guess it will depend on how many URLs you currently have, and how easy it'd be to redirect them all.

Perhaps you can add some code to your current pages that will redirect to their new homes for a certain amount of time, and then you can remove that code permanently. This would be good for dynamic links like blogs and such, and not require you to really add anything except a redirect code in CodeIgniter.

I hope that makes sense, it's late here. Big Grin

thanks for the input!

I'd like to redirect the old url's to it's new path but per requirements, the client wants it to redirect to it's homepage Sad

This should i suggest to them for better SEO!

I also, tried your suggestion about redirecting old urls to it's new path..and it works

what i did is i re-route my old url to a new member function in my controller

old path:

new path:

page/view/$1 = 'page/redirect_old_path/$1'
page/$1 = 'page/new_url_page/$1'

where the redirect_old_path member function redirects to 'page/new_url_page/$1'

Im just a newbie in CI, any suggestion on how to improve this approach are welcome!

Thanks Aken for the help!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.