lie2815
(Franz)
September 30, 2011, 10:19pm
1
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.
ManInTheBox
(Stankovic Zarko)
October 1, 2011, 12:41am
2
Try this one:
'<id:\w+>.html' => 'site/page',
It should work, of course you’ll need to properly hide index.php
phtamas
(Phtamas)
October 1, 2011, 6:56am
3
URL suffix can be specified for individual rules:
'<id:\w+>' => array('site/page', 'urlSuffix' => '.html'),
lie2815
(Franz)
October 2, 2011, 10:33pm
4
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?
ManInTheBox
(Stankovic Zarko)
October 5, 2011, 8:51am
5
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.
lie2815
(Franz)
October 5, 2011, 2:49pm
6
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.