简体   繁体   English

Codeigniter和重定向过期的URL

[英]codeigniter and redirecting on expired urls

I have a site built with codeigniter. 我有一个使用codeigniter构建的网站。 Everything is working great except, I have a news area with a setof pages that disappear after a set amount of time. 一切工作正常,但我有一个新闻区域,其中包含一组页面,这些页面在一定时间后消失。 When people access the old links I want to redirect them to a different page. 当人们访问旧链接时,我想将其重定向到其他页面。 The rub is the links are www.site.com/controller/function/page-id-with-numbers-0098468854. 麻烦之处是链接是www.site.com/controller/function/page-id-with-numbers-0098468854。 If someone accesses the link it works great. 如果有人访问该链接,则效果很好。 What i would like to route away is mistyped page ids and deleted ids redirect to a sorry page moved page, or better yet homepage with an alert or message. 我想绕开的是输入错误的页面ID和删除的ID,这些页面ID重定向到对不起的页面移动页面,或者更好的是带有警报或消息的主页。

You can use show_404() CI Document here 您可以在此处使用show_404() CI文档

At first, parse uri segment with this and get page ID 首先,用这个解析uri段并获取页面ID

$this->uri->segment(n);

Check DB page id exist or not and show 404 page like below: 检查数据库页面ID是否存在,并显示404页面,如下所示:

if(mysql_num_rows($result) == 0)
{
   show_404();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM