>我有一个应用程序,重写后的URL是这样的
http://www.domain.com/product/seller/product_id
一个示例链接是
http://storeiown.com/product/kitchenking/92013
这没关系,但我需要将产品的标题包含在 url 中
http://storeiown.com/product/a-very-nice-electric-cooker-by-kitchenking/92013
我也做到了这一点,一切都很好。
现在,我希望所有不包含标题的网址都重定向到这个网址。例如,如果用户从没有标题的 url 登陆,则应将他们重定向到包含 url 中标题的页面版本。
我该如何做到这一点。有关其他信息,我在应用程序中使用CodeIgniter,如果这样可以使其更容易的话。
你可以用这种方式来做我使用的方式。在上一页中,在顶部键入以下内容:-
<?php
session_start();
$_SESSION['mainpass']= '0';
?>
在下一页中,在页面顶部对此进行编码:-
<?php
session_start;
if(isset($_SESSION['mainpass'])) {
//run the current page
}else{
header("location: www.domain.com");
}
?>
如果您使用的是代码点火器,则可以尝试以下操作。
$seg3 = $this->uri->segment(3);
if(is_numeric($seg3)){
//The user has come without the header because the third segment is numeric thus probably using the product id.
//Therefore, redirect again to the proper link after getting the heading from your db
} else {
// do nothing
// the seg3 is not numeric means it probably came through normal preferred way
}
并且为了使用
$this->uri->segment(3);
您需要
自动加载网址帮助程序
需要时手动加载