Welcome Guest, Not a member yet? Register   Sign In
codeigniter routed segments incorrectly converting dashes to underscores with nginx
#1

[eluser]jayhung[/eluser]
I have been struggling with this issue for a few days. Been unsuccessful searching codeigniter forums, nginx forums, stackoverflow, as well as the general web. I posted this new question on stackoverflow, but thought perhaps some of you here may have a solution or have come across this in the past:

http://stackoverflow.com/questions/14676...es-with-ng

To summarize, on an nginx install, my uri segments is showing correct parts for my URI, including dashes for my slugs. However, the same uri rsegments (routed segments) shows the slug with all dashes converted to underscores (this is also how it is passed as a param to my controller method).

I've traced this to line 389 of Router.php, in the _parse_route() method, at the call to

Code:
return $this->_set_request(explode('/', $val));

More info in the stackoverflow link, as well as my actual nginx configs.

I am using CodeIgniter 2. The same code has been working fine on Apache installs for multiple deployments.
#2

[eluser]boltsabre[/eluser]
I think you'll have to extend the Router class with a MY_Router (making sure it extends CI_Router obviously!). Then, whatever the function is that contains line 389, copy and paste it into your new MY_Router file, and change the functionality, a php str_replace() on $val should do the trick, just replace all underscores (_) with dashes (-).

Hope that helps?
#3

[eluser]Aken[/eluser]
He shouldn't have to extend anything. It works fine on Apache, something with Nginx is messing with it.

I've never used Nginx, so I'm not much help. I can tell you, though, that the start/end characters in your route regex are unnecessary - Router.php will put them in for you.
#4

[eluser]jayhung[/eluser]
Extending the router class and replacing underscores back to dashes isn't the right solution. That would potentially change method names from underscores to dashes without some logic to handle those. Any underscores that were originally underscores would also be replaced to dashes, which isn't the solution.

My initial feeling was nginx, but that also doesn't sound correct since the conversion seems to be happening in php. The array from the explode() statement has dashes before the call to _set_request(), and has underscores after the call has been made. That should be strictly within php - it doesn't even touch any additional codeigniter logic. Nevertheless, I may attempt to setup another environment w/ nginx 1.2.6 (latest stable) to do further testing.
#5

[eluser]jayhung[/eluser]
I have found the problem - developer error. The deploy script in use was not properly deleting an old MY_Router.php file from the server (this file did not exist locally nor on the apache installs).

Codeigniter, PHP, and nginx are all working as expected.

Thanks all for the comments.




Theme © iAndrew 2016 - Forum software by © MyBB