urlSuffix should be enforced when set

When having this config:




'urlManager' => array(

	'urlSuffix' => '.html',

	'rules' => array(

		'contact' => 'site/contact',

	),

),




http://example.com/contact

http://example.com/contact.html

Both will work. This is kind of irritating. I suggest to enforce the urlSuffix when the requested path is != ‘/’ or doesn’t end with an ‘/’. Or maybe add a bool config var like “enforceUrlSuffix”? Let me know what you think. :)

this is pretty good idea!, i did fix for it myself but i think framework core should have this option

having a url config setting for that would be welcomed. good idea.

I’ve just noticed that the url-suffix is already enforced when useStrictParsing is enabled. I didn’t noticed that before because it doesn’t work when urlSuffix is set to ‘/’ (my preferred suffix) :huh:

Bug takes place on line 592 in CUrlManager.php (1.1b)


if($urlSuffix!='' && $urlSuffix!=='/')

has to be:


if($urlSuffix!=='')

I’ll submit a ticket for this later. ;)

// But still I’m not really happy with this. For example if someone requests ‘/test’ and my suffix is set to ‘/’, he will get a 404. Now I could disable strictParsing and enforce the suffix with a special funtion (within a parent controller) that redirects to the correct url. But when strictParsing is disabled, it’s possible to access pages with controller/action (eg example.com/site/index), so it’s possible to override the defined rules (they don’t have to match anymore).

Maybe add a property to the urlManager that (when set to true) allows a missing urlSuffix even if strictParsing is enabled? I think this would be a good solution. Otherwise I’d need to force the suffix with .htaccess or via onBeginRequest when useStrictParsing is enabled. That’s kind of dirty.

What you think? I know, it’s a minor thing though…