【问题标题】:Redirect users to Long URL将用户重定向到长 URL
【发布时间】:2013-11-12 05:01:50
【问题描述】:

我有一个应用程序,重写后的 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 登陆,他们应该被重定向到 url 中包含标题的页面版本。

我如何做到这一点。对于信息附加信息,我在应用程序中使用 CodeIgniter,如果这样更容易的话。

【问题讨论】:

  • mod_rewrite 不会工作吗?此外,您应该考虑将产品名称与品牌分开,例如 http://storeiown.com/product/kitchenking/a-very-nice-electric-cooker/92013,因为将所有信息放在一个块中会降低索引和用户体验的实用性。

标签: php codeigniter url-rewriting url-routing url-redirection


【解决方案1】:

您可以按照我使用的方式进行操作。在上一页的顶部键入:-

<?php
session_start();
$_SESSION['mainpass']= '0';
?>

在下一页的顶部代码中:-

<?php
session_start;
if(isset($_SESSION['mainpass'])) {
//run the current page
}else{
header("location: www.domain.com");
}
?>

【讨论】:

    【解决方案2】:

    如果您使用的是 codeigniter,您可以尝试以下方法。

    $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);
    

    你需要

    • 自动加载网址助手

    • 需要时手动加载

    【讨论】:

      猜你喜欢
      • 2017-07-15
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-08
      • 1970-01-01
      • 2019-05-14
      相关资源
      最近更新 更多