reg 表达式 & 问题Codeigniter 中的路线
我在使用 Codeigniter 和我的表达式中的路线时遇到问题
我有一个如下所示的 URL(对于优惠页面):
www.site.com/company/offers/view/newsarticle/219
和如下所示的路线:
$route['([a-z0-9_-]+)/offers/view/([a-z0-9]+)/([0-9]+)'] = "offers/view/$1/$2/$3";
我有上述路线设置,因此是否应该转到优惠控制器和视图函数并传递 3 个参数(公司、新闻文章、219)
它工作得很好,但是如果第 4 个 uri 段包含和“-”,它就会中断并给我一个 404 页面 例如,
这有效
www.site.com/company/offers/view/newsarticle/219
,但这不起作用
www.site.com/company/offers/view/news-article/219
任何人都可以解释我在表达式中做错了什么吗?谢谢
I am having an issue using the routes in Codeigniter and my expressions
I have a URL like follows (for a offers page):
www.site.com/company/offers/view/newsarticle/219
and a route like follows:
$route['([a-z0-9_-]+)/offers/view/([a-z0-9]+)/([0-9]+)'] = "offers/view/$1/$2/$3";
I have the above route setup so if should go to the offers controller, and the view function and pass the 3 parameters (company, newsarticle, 219)
It works all fine however if the 4th uri segment contains and '-' it breaks and gives me a 404 page
eg
This works
www.site.com/company/offers/view/newsarticle/219
But this doesn't
www.site.com/company/offers/view/news-article/219
Can anyone explain what I've done wrong with the expressions? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的表达式不允许使用连字符,
应
注意
[a-z0-9\-]
中的\-
。\
字符对连字符进行转义,以告诉表达式引擎它不是范围运算符。Your expression doesn't allow a hyphen character
Should be
Note the
\-
in the[a-z0-9\-]
. The\
character escapes the hyphen to tell the expression engine that it's not a range operator.