gpt4 book ai didi

php - 只允许在 Codeigniter 中看到路由中指定的 URL

转载 作者:可可西里 更新时间:2023-11-01 00:48:29 26 4
gpt4 key购买 nike

如果我有一个名为 articles 的 Controller ,它有一个名为 view_articles 的方法,用户可以输入 http://example.com/articles/view_articles/some-post并让它返回一个页面。

我已将路线指定为 http://example.com/article/post-name .我怎样才能使路由中指定的 URL 可见?有没有办法让 articles/view_articles/some-post 显示 404 而不是显示与路由 URL 相同的页面?

出于 SEO 目的,我正在努力防止重复。

最佳答案

您始终可以通过在 routes.php 文件中正确定义路由来将默认路由设置为 404 页面:

$routes['article/(:any)'] = 'articles/view_articles/$1';

$routes['(:any)'] = 'main/e404';

如 CodeIgniter 用户指南所述:

Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

所以你基本上可以在文件的开头定义你想要看到的所有内容,并在最后一行阻止所有其他内容。

至于你的主要(可以是任何其他) Controller 的 404 方法 -

function e404() {
show_404();
}

关于php - 只允许在 Codeigniter 中看到路由中指定的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12626700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com