Case Sensitive URLs #336

Closed
tonyeung opened this Issue Feb 16, 2012 · 9 comments

Projects

None yet

3 participants

@tonyeung

Not really a bug, but something that left me scratching my head for awhile trying to figure out why my project wouldn't work in production. Is there a configuration to make the URLs not case sensitive?

@greut
greut commented Feb 16, 2012

Do you have a real problem to start from? I cannot find any problem messing up with controller or action case. For the args, your application have to deal with that though.

@tonyeung

For example, lets say i created a new lithium site with no modifications.
I run the helloworld sample by doing www.samplesite.com/samplelithium/helloworld where samplelithium would be the app folder and helloworld is the controller name. i get this error:
Fatal error: Uncaught exception 'lithium\core\ClassNotFoundException' with message 'Class Helloworld of type controllers not found.' in /home/wsr/public_html/sample/libraries/lithium/core/Libraries.php:621 Stack trace: #0 /home/wsr/public_html/sample/libraries/lithium/core/Libraries.php(632): lithium\core{closure}('lithium\core\Li...', Array) #1 /home/wsr/public_html/sample/libraries/lithium/action/Dispatcher.php(197): lithium\core\Libraries::instance('controllers', 'Helloworld', Array) #2 /home/wsr/public_html/sample/libraries/lithium/core/StaticObject.php(119): lithium\action{closure}('lithium\action...', Array, NULL) #3 /home/wsr/public_html/sample/libraries/lithium/action/Dispatcher.php(201): lithium\core\StaticObject::_filter('_callable', Array, Object(Closure)) #4 /home/wsr/public_html/sample/libraries/lithium/core/StaticObject.php(75): lithium\action\Dispatcher::_callable(Object(lithium\action\Request), Array, Array) #5 /home/wsr/public_html/sample/libraries/lithium/action/Dispatcher.php(121): lithium\core\S in /home/wsr/public_html/sample/libraries/lithium/action/Dispatcher.php on line 199

@greut
greut commented Feb 16, 2012

What if you have a HelloworldController? helloworld cannot be translated into HelloWorld automagically unless you do something yourself, but hello_world will.

It's done in the Dispatcher::applyRules() using Inflector::camelize().

I'm pretty sure you can add some rules for your specific case in your config.

@tonyeung

I suppose a better question would be why would you have Helloworld or HelloWorld or helloworld controller?
From a user standpoint, should they need to remember the casing of a url? isn't the whole point of userfriendly routes to simplify what a user has to type in if they want to type in a url?
As I said, this isn't really a bug, its just something of a pet peeve and I was wondering if the powers that be would agree or not?

@greut
greut commented Feb 16, 2012

If you want helloworld then you'll create the Helloworld controller. URL are case sensitive by default on the web and lithium reflects that.

do not use MiXeD case text in URLs since people can't remember the difference between upper-case and lower-case characters: all-lowercase URLs are usually preferred (domain names are less of a problem since they are case-insensitive - usability would increase if webservers would ignore case in resolving URLs)”
http://www.useit.com/alertbox/990321.html

You can always filter Dispatcher::run() to change the Request::$url to a lowercase one to support any kind of URL as inputs.

@tonyeung

so if I change the URL paramter to all lowercases, it won't affect the resolving of controller names?

@greut
greut commented Feb 16, 2012

For example? Testing that is pretty straightforward it seems.

@tonyeung

It would be, I was hoping someone would have tried and knows off the top of their heads what the repercussions of forcing a lowercase URL will be. I'll try it after I deliver my current project, since its a would be nice rather then a has to be there kind of thing.

@nateabele
Member

What you're talking about is not a bug related to case-sensitivity issues, but two logically different URLs: one is /helloworld, and the other is /hello_world. In terms of Lithium, the second URL is the correct one. The fact that the first one works on your local machine is merely a coincidence, since your local machine has a case-insensitive filesystem. To be clear, the fact that it happens to work doesn't make it any less wrong. This issue would otherwise never come up anywhere (i.e. Lithium would never generate an incorrect URL, just because your filesystem is case-insensitive), so I don't think we can really call this a bug.

Hopefully that explains it for you, and you have a better understanding of how Lithium handles URLs.

@nateabele nateabele closed this Feb 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment