只允许在 Codeigniter 中看到路由中指定的 URL's [英] Only allow URL's specified in routes to be seen in Codeigniter
问题描述
如果我有一个叫做文章的控制器,它有一个叫做 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.
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->segment(n)
作为 URI 类位于 view_articles
内,如果 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's的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!