CodeIgniter Forums
How can I do a redirect with CodeIgniter? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How can I do a redirect with CodeIgniter? (/thread-991.html)



How can I do a redirect with CodeIgniter? - alexandervj - 02-04-2015

I had a wordpress site before I built my site with codeigniter. I was getting a fair amount of traffic to those wordpress pages but replaced the site with a totally different layout and codeigniter instead of wordpress.

I have a lot of pages cached by Google in the form of www.website.com/category/post. I have a 1 page style site now. I'm not sue how to do the redirects from the old pages to the new page. Any help you can give is appreciated


RE: How can I do a redirect with CodeIgniter? - mwhitney - 02-04-2015

You have a number of options, including setting a default controller with a remap function to redirect requests for known locations. Given that the old URLs are in the form category/post, though, you may just want to create a category controller to handle those (if your routes and URL rewrites are setup that way).

It may even be possible to handle this in your routes config, but that really depends on how you intend to handle those requests.


RE: How can I do a redirect with CodeIgniter? - Rufnex - 02-04-2015

As mwhitney said, it depends on your data. What you need is a matching key for e.g. an database ID. Then you can remap you're old link structure as route roule.

PHP Code:
$route['/category/post/(:any)'] = '/your_controller/$1'

In the example above you have an old url like (http://.../category/post/123). The visitor will be redirect by the roule to http://.../your_controller/123


RE: How can I do a redirect with CodeIgniter? - alexandervj - 02-04-2015

Thanks! I will try the route option and let you know