只允许在 Codeigniter 中看到路由中指定的 URL's [英] Only allow URL's specified in routes to be seen in Codeigniter

查看:52
本文介绍了只允许在 Codeigniter 中看到路由中指定的 URL's的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个叫做文章的控制器,它有一个叫做 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 可见?有没有办法让文章/view_articles/some-post 显示 404 而不是显示与路由 URL 相同的页面?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆