Yii2 UrlManager 在期间中断 [英] Yii2 UrlManager Breaks On Periods

查看:28
本文介绍了Yii2 UrlManager 在期间中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 yii2 urlManager 创建一个漂亮的 URL.它接收一个参数,然后根据它查找用户.不幸的是,如果参数包含句点,它根本不会运行并重定向到 404 页面.

I am currently using yii2 urlManager to create a pretty URL. It receives a parameter and then looks up users based on it. Unfortunately, if the parameter contains a period, it won't run at all and redirects to a 404 page.

所以,

mysite.com/me/jbroad 

完美运行,但是

mysite.com/me/j.broad 

返回 404 页面.

这是我的网址管理器代码

Here is my url manager code

'urlManager' => [
     'enablePrettyUrl' => true,
     'showScriptName' => false,
     'rules' => [
         '' => 'site/index',
         'me/<id:\w+>' => 'kit/page',
         'generate/<id:\w+>' => 'kit/generate',
          '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
     ],
],

推荐答案

您正在使用带有标记 \w+ 的正则表达式匹配任何单词字符(等于 [a-zA-Z0-9_]) 并且不包括句点或 ..

You are using the regex with token \w+ which matches any word character (equal to [a-zA-Z0-9_]) and does not include a period or ..

因此将其更改为 [\w\.]+ 并且您的规则现在将是

so change it to [\w\.]+ and your rule will now be

me/<id:[\w\.]+>' => 'kit/page',

这篇关于Yii2 UrlManager 在期间中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆