只允许在Codeigniter中看到路由中指定的URL [英] Only allow URL's specified in routes to be seen in Codeigniter
问题描述
如果我有一个名为articles的控制器,它有一个名为view_articles的方法,则用户可以输入 http://example.com/articles/view_articles/some-post ,并返回页面。
If I have a controller called articles, which has a method called view_articles, a user can type in http://example.com/articles/view_articles/some-post and have it return a page.
我已指定路线为 http://example.com/article/post-name 。我如何使它只有在路由中指定的URL是可见的?有没有办法让article / view_articles / some-post显示404而不是显示与路线网址相同的网页?
I have specified a route to be http://example.com/article/post-name. How can I make it so that only the URL specified in the route is visible? Is there a way for articles/view_articles/some-post to show a 404 instead of showing the same page as the route URL?
我试图防止SEO的重复目的。
I am trying to prevent duplication for SEO purposes.
推荐答案
使用 $ this-> uri-> c $ c>作为
view_articles中 URI类的一部分
如果URI包含 view_articles
作为第二个细分,则将流量重定向到您的路线。
Use $this->uri->segment(n)
as part of the URI class inside of view_articles
to redirect traffic to your route if the URI contains view_articles
as it's second segment.
这篇关于只允许在Codeigniter中看到路由中指定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!