CodeIgniter Forums
[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: [Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls (/thread-24149.html)

Pages: 1 2


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-01-2009

[eluser]ehicks727[/eluser]
I'm re-coding an entire site in CodeIgniter. The current site uses url paramters, such as this...

http://www.sportsfeatures.com/index.php?section=olympic-article-view&title=London 2012 captured for all time in Portrait Gallery project&id=46145

For SEO purposes (getting Google to re-index my site over time with the new url structure and avoiding 404s) I'm trying to set up some routing to 301 redirect the old pages to the new pages.

I'm keying into id= so if I can get the id of the article into a controller, then I'm good. I'm just having problems getting there and could use some help.

I've tried this..

Code:
$route['index.php?(:any)'] = 'reroute/$1';

But it comes back with "The URI you submitted has disallowed characters."

How can I carve out the id=#### and send it to a controller called reroute?

Thanks for your help.


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-01-2009

[eluser]ehicks727[/eluser]
Anyone??


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]ehicks727[/eluser]
Ok, after reading a lot of posts on this topic, I'm starting to think that I can't do this with a CI solution.

However, can any of you regex gurus help me out with a mod_rewrite solution? If my incoming url looks like this...

http://www.sportsfeatures.com/index.php?section=olympic-article-view&title=London 2012 captured for all time in Portrait Gallery project&id=46145

is there a way I can just capture the ID and send it to my controller? So in this case, mod_rewrite would change this to...

http://www.sportsfeatures.com/reroute/story/46145


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]BrianDHall[/eluser]
If you enable query strings in CI (in config.php), and probably set your uri_protocol to PATH_INFO in config.php.

Then if you have a debugger you can just set a breakpoint in routes.php and you can see that $_GET still exists for your use.

Then you can just do this in your routes file:

Code:
if ($_GET['id'])
{
    $route['(:any)'] = 'reroute/story/' . $_GET['id'];
}

I tested it on my localhost and it works perfectly. If a ? and somewhere an id= exists, it will trigger the route and away it will go.

If it gives you problems I like testing my reroutes against a page (function) that has nothing but $this->output->enable_profiler(TRUE);


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]Phil Sturgeon[/eluser]
You cannot use routes to map sections of your query string. For that, use mod_rewrite in your .htaccess file.


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]BrianDHall[/eluser]
[quote author="Phil Sturgeon" date="1257195189"]You cannot use routes to map sections of your query string. For that, use mod_rewrite in your .htaccess file.[/quote]

Sure you can! *points up*


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]Phil Sturgeon[/eluser]
Ha, you dirty b*tch!

Ok yeah that will work.

Lemme rephrase: "You cannot use regular expressions or patterns on routes".


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]BrianDHall[/eluser]
[quote author="Phil Sturgeon" date="1257199905"]Ha, you dirty b*tch!

Ok yeah that will work.

Lemme rephrase: "You cannot use regular expressions or patterns on routes".[/quote]

Yes, well we can't prosecute you for that. Smile

And true, you have to think "outside the array" to accomplish GET-based routing, unless you want to go a hackin'.


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]ehicks727[/eluser]
[quote author="BrianDHall" date="1257194434"]If you enable query strings in CI (in config.php), and probably set your uri_protocol to PATH_INFO in config.php.

Then if you have a debugger you can just set a breakpoint in routes.php and you can see that $_GET still exists for your use.

Then you can just do this in your routes file:

Code:
if ($_GET['id'])
{
    $route['(:any)'] = 'reroute/story/' . $_GET['id'];
}

I tested it on my localhost and it works perfectly. If a ? and somewhere an id= exists, it will trigger the route and away it will go.

If it gives you problems I like testing my reroutes against a page (function) that has nothing but $this->output->enable_profiler(TRUE);[/quote]

Thank you for replying.. I'm going to give it a shot and I'll let you know.


[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls - El Forum - 11-02-2009

[eluser]ehicks727[/eluser]
Ok, I set to PATH_INFO and enabled query strings, and entered that control statement in my routes file. It's just going to the home page now. It never makes it to my reroute controller. I just did an echo "HERE"; exit; in that controller and I never get there.

Should I add some characters to this, or doesn't that matter?
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';