[英]Regex to exclude categories from url in Codeigniter. How?
我想拥有
这些网址作为我页面上的类别:
http://example.com/en/articles //for list of all
http://example.com/en/articles/cars //for list of all cars articles
http://example.com/en/articles/nature //for list of all nature acrticles
http://example.com/en/articles/sport //for list of all sport articles
我正在使用i18n,这就是为什么我还有另一个链接,例如:
http://example.com/fr/articles //for list of all
http://example.com/fr/articles/cars //for list of all cars articles
http://example.com/fr/articles/nature //for list of all nature acrticles
http://example.com/fr/articles/sport //for list of all sport articles
这很容易,我在其中调用了一个controllers.php和an控制器,它具有汽车,自然,运动和一切正常的功能。
但是,无论文章属于什么类别,我都希望有这样的文章:
http://example.com/en/articles/article-about-cars http://example.com/en/articles/article-about-nature
因此,查看全文时,类别从url中消失了。
我正在使用i18n,因此我的路线如下所示:
$route[’^en/articles/(.+)$’] = “articles/show_full_article/$1”;
$route[’^fr/articles/(.+)$’] = “articles/show_full_article/$1”;
但是每次都调用show_full_article函数,因为它在第二段中。
因此,我需要以某种方式重建正则表达式:
$ route ['^ en / articles /(.+)$'] =“ articles / show_full_article / $ 1”;
排除汽车,自然和运动功能。 我只有3个类别,因此手动键入没什么大不了的。
请,如果您知道如何在routes.php中键入正则表达式以排除这三个类别,那么codeigniter不再将它们视为文章名称,请告诉我。 我会非常感激。
预先感谢您的任何建议。
您可能要为此使用负前瞻(?!...)
。
在您的情况下:
$route['^en/articles/(?!(?:cars|nature|sport)$)(.+)$'] =
这样可以确保(.+)
不能是这些单词之一。 它需要包装在(?:..)$
以便它也与字符串的末尾匹配,否则断言也将阻止natureSMTHNG
和类似的较长术语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.