使用 Yii urlManager 处理非标准 url
我需要使用像
这样的网址,例如: api.wwwhost.com/index.php?r=people.top
所以,我尝试编写模式
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'useStrictParsing'=>true,
'rules'=>array(
'<controller:\w+>.<action:\w+>' => '<controller>/<action>',
),
),
,但它不起作用。据我所知,符号“。”不包含在“\w+”中。
我的错误在哪里?
I need to use urls like <controller>.<action>
, for example: api.wwwhost.com/index.php?r=people.top
So, I've tried to write pattern
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'useStrictParsing'=>true,
'rules'=>array(
'<controller:\w+>.<action:\w+>' => '<controller>/<action>',
),
),
but it does not work. As I know, symbol "." not included in "\w+".
Where is my mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,当处于“path”模式(
'urlFormat'=>'path'
)时,我无法使用index.php?r=people/top
样式 URL 。当我处于path
模式时,我的?r=
样式 URL 都不起作用。你也有同样的经历吗?当我处于“get”模式时(
'urlFormat'=>'get'
),但在 get 模式下,URL 规则不会被处理,并且似乎默认只使用 '/ ' 作为分隔符。当我使用这种样式 URL 时,您的代码确实对我有用:
设置“路径”模式时(即
'urlFormat'=>'path'
),请务必拥有您的.htaccess
文件正确设置以使用它(隐藏index.php 文件)。更多信息请参见 有关 URL 的 Yii 指南。For me, when in "path" mode (
'urlFormat'=>'path'
), I cannot use theindex.php?r=people/top
style URLs. None of my?r=
style URLs work when I am inpath
mode. Do you experience the same thing?They DO when when I am "get" mode (
'urlFormat'=>'get'
), but in get mode the URL rules are not processed, and it appears to default to only use '/' for delimiters.You code DID work for me when I used this style URL:
When "path" mode is set (i.e.
'urlFormat'=>'path'
), be sure to have your.htaccess
file set up correctly to use it (hiding the index.php file). More info here in the Yii Guide about URLs.