Simple route problem

Hey folks,

I am trying to add this simple route to my urlManager:


'<id:[^\.]+>\.html'=>'site/page',

What I want is for pages like "faq.html" to be forwarded to the site/page action with the id parameter being set to "faq".

And that works fine.

However, when I try to create the URL for site/page by calling


Yii::app()->createUrl('site/page', array('id' => 'faq'))

, I unfortunately get a link to "faq/.html".

How can I fix that?

P.S.: I cannot just use the URL suffix feature, as I don’t want all my pages to have the html extension.

Try this one:




'<id:\w+>.html' => 'site/page',



It should work, of course you’ll need to properly hide index.php

URL suffix can be specified for individual rules:




'<id:\w+>' => array('site/page', 'urlSuffix' => '.html'),



Thanks, guys.

Unfortunately, the urlSuffix option does not seem to work - probably because I have another rule just like that, just without the suffix.

Anyway, I suppose this did not work because the slash before the dot before the "html" is not removed when generating URLs from the routes.

Is that a bug?

I think it is not a bug. RegEx is performed in a pair of <> and everything after closing > is treated as a string which is appended to matched parameter.

I think it matches the route, though.

It just didn’t properly create an URL based on that route.

Since you have 2 rules that are the same, only 1 has a suffix, you could set the rule-without-suffix to parsingOnly=>true, so that it matches for inbound requests, but not for creating urls within the app.