我的新闻有旧网址,例如http://example.com/mynew/35/this-is-the-title http://example.com/mynew/35/this-is-the-title,其中 35 是新闻的 ID。现在我的新网址就像http://example.com/mynew/this-is-the-title http://example.com/mynew/this-is-the-title我不知道如何将所有旧新闻网址重定向到新网址。任何想法?谢谢
在 codeigniter 的 paths.php 中,我有:
$route['news'] = 'news/index';
$route['news/(:num)'] = 'news/index/$1';
$route['mynew/(:any)'] = 'news/mynew/$1';
在这种情况下,http://example.com/mynew/35/this-is-the-title
你有桌子的ID,你可以很容易地找到它。但如果你用这个http://example.com/mynew/this-is-the-title
没有任何唯一标识符,因此您无法从表中检索数据。
要存档此内容,您可以执行以下操作
- 使用 URL slug 更改表(列名
url_slug
or slug
)
- 创建通用控制器方法。根据你的代码
index()
under news
(控制器名称)
- 创建公共新闻视图
注意:Slug 应包含唯一的文本标识符来标识确切的新闻(与主键相同)
Title - this is an news title regarding php
slug - regarding-php
在控制器中
public function index($slug)
{
if (!empty($slug)) {
# code...
#write select code and load the common view
$data['title'] = "my Heading" ;
$data['content'] = "my para............." ;
$data['footer'] = "foot" ;
$this->load->view('news/common',$data);
}
else
{
}
}
In View
# echo will also work
<div id="title"><?= print_r($title); ?></div>
<div id="content"><?= print_r($content); ?></div>
<div id="footer"><?= print_r($footer); ?></div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)