假设我有一个 Controller “文章”,但我希望它显示为子文件夹(例如“博客/文章”),我可以添加这样的路由:
$route['blog/articles'] = 'articles';
$route['blog/articles/(:any)'] = 'articles/$1';
这很好用,现在唯一的问题是 example.com/articles
和 example.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/