CodeIgniter Forums
program redirect of links - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: program redirect of links (/showthread.php?tid=63155)



program redirect of links - Andryshok - 09-30-2015

Hi to everything, whether will share who the solution of one problem
the reference of a look http://my_syte/catalog/item/my_product is had
it is necessary to make 301 redirects for example on the link http://my_syte/id/2
that is the old link is stored in a database how to realize such redirection?

BAD English ON Blush


RE: program redirect of links - InsiteFX - 10-01-2015

Apache mod rewrite:

htaccess Tricks


RE: program redirect of links - Andryshok - 10-01-2015

(10-01-2015, 03:48 AM)InsiteFX Wrote: Apache mod rewrite:

htaccess Tricks

your decision doesn't approach, it is necessary setting up the link from the control panel the concrete page of the site


RE: program redirect of links - slax0r - 10-01-2015

I am having trouble understand what you want. So just to clarify, your current URL is "http://my_syte/catalog/item/my_product", but you want it to be "http://my_syte/id/2"?

In either way, this is a weird relation between the two, and you will have to manually map all values. In your application/config/routes.php you can do:
PHP Code:
$route["id/2"] = "catalog/item/my_product"



RE: program redirect of links - mwhitney - 10-01-2015

You could also use a _remap() function in your controller to lookup the correct information and perform the redirect.


RE: program redirect of links - slax0r - 10-01-2015

(10-01-2015, 07:14 AM)mwhitney Wrote: You could also use a _remap() function in your controller to lookup the correct information and perform the redirect.

Not really in this case. If you visit id/2 and you do not have a controller named id and method named 2, the router will not know to which controller to route to, and fail to hit your _remap() in your base controller.


RE: program redirect of links - mwhitney - 10-02-2015

(10-01-2015, 11:06 PM)slax0r Wrote:
(10-01-2015, 07:14 AM)mwhitney Wrote: You could also use a _remap() function in your controller to lookup the correct information and perform the redirect.

Not really in this case. If you visit id/2 and you do not have a controller named id and method named 2, the router will not know to which controller to route to, and fail to hit your _remap() in your base controller.

I wouldn't put a _remap() function in the base controller. In fact, I think that would be a bad idea, because most of my controllers have no need for a _remap(). I would create a controller named Id with a _remap() function to point it wherever the calls need to go. If I needed to remap more URLs than just those with 'id' in the first segment, I would make more controllers.

If this was a significant problem, I would create a library to rewrite the routes and override the router to load the library. However, that would be my last-ditch approach, as it indicates that all other attempts to fix the problem have failed.