codeigniter - 在 CodeIgniter 中重新路由页面时如何防止重复内容?

标签 codeigniter routing controller

假设我有一个 Controller “文章”,但我希望它显示为子文件夹(例如“博客/文章”),我可以添加这样的路由:

$route['blog/articles'] = 'articles';
$route['blog/articles/(:any)'] = 'articles/$1';

这很好用,现在唯一的问题是 example.com/articlesexample.com/blog/articles 都使用 Articles Controller ,因此解决了相同的内容。有没有办法防止这种情况发生?

在人们不理解的情况下增加一点清晰度:

  • 在此示例中,我没有“博客” Controller ,但我希望“文章”等出现在该子文件夹中(这是一个组织的东西)。
  • 我可以有一个带有“文章”功能的博客 Controller ,但我可能有一堆“子 Controller ”并且想要分离功能(否则我最终可能会在博客 Controller )。
  • 我希望 example.com/articles 返回 404,因为这不是正确的 URL,example.com/blog/articles 是。

最佳答案

把它塞进你的 Controller :

function __construct()
{
    parent::Controller();

    $this->uri->uri_segment(1) == 'blog' OR show_404();
}

关于codeigniter - 在 CodeIgniter 中重新路由页面时如何防止重复内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3202875/

相关文章:

javascript - 限制用户在当前时间之后输入 HTML <input type = "time">

asp.net - 我可以从站点地图生成 ASP.NET MVC 路由吗?

string - Symfony4 预期字符串但得到字符串

java - 使用 Java Spring Controller 从表单读取值

asp.net-mvc - MVC 路由和区域 - 如何构建路由以匹配区域中默认 Controller 上的操作?

javascript - 将数据从请求对象传递到模板node.js

javascript - AJAX 在我的项目中不起作用

php - CodeIgniter 自动加载特定类

codeigniter - 注册成功后如何在主页显示成功消息(不是警告框)

Angular 5 空错误 : no elements in sequence while making child routes