CodeIgniter Forums

Full Version: program redirect of links
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Apache mod rewrite:

htaccess Tricks
(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
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"
You could also use a _remap() function in your controller to lookup the correct information and perform the redirect.
(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.
(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.