how to create 301 redirect in codeigniter

#1
[eluser]achilles_085[/eluser]
hello,

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)

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

Check out:
http://ellislab.com/codeigniter/user-gui...elper.html

(At the very bottom of the page.)

#3
[eluser]achilles_085[/eluser]
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?

#4
[eluser]Aken[/eluser]
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.

#5
[eluser]achilles_085[/eluser]
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

#6
[eluser]Aken[/eluser]
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 http://www.example.com/blog/12/this-is-a-blog-entry. If your new URL structure is something like http://www.example.com/newblog/this-is-a...entry.html, 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

#7
[eluser]achilles_085[/eluser]
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:
page/view/$1

new path:
page/$1

routes:
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.