reg 表达式 & 问题Codeigniter 中的路线

发布于 2024-12-15 22:43:41 字数 600 浏览 2 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思 2024-12-22 22:43:41

您的表达式不允许使用连字符,

([a-z0-9_-]+)/offers/view/([a-z0-9]+)/([0-9]+)

([a-z0-9_-]+)/offers/view/([a-z0-9\-]+)/([0-9]+)

注意 [a-z0-9\-] 中的 \-\ 字符对连字符进行转义,以告诉表达式引擎它不是范围运算符。

Your expression doesn't allow a hyphen character

([a-z0-9_-]+)/offers/view/([a-z0-9]+)/([0-9]+)

Should be

([a-z0-9_-]+)/offers/view/([a-z0-9\-]+)/([0-9]+)

Note the \- in the [a-z0-9\-]. The \ character escapes the hyphen to tell the expression engine that it's not a range operator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文