Welcome Guest, Not a member yet? Register   Sign In
[Solved] Routing issue - need to redirect from url parameterized pages to new CodeIgniter nice urls
#1

[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?...tle=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.
#2

[eluser]ehicks727[/eluser]
Anyone??
#3

[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?...tle=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
#4

[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);
#5

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

[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*
#7

[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".
#8

[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'.
#9

[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.
#10

[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~%.:_\-';




Theme © iAndrew 2016 - Forum software by © MyBB