【问题标题】:how to make codeigniter dynamic url search engine friendly如何使 codeigniter 动态 url 搜索引擎友好
【发布时间】:2015-02-04 13:12:33
【问题描述】:

问题: 如何让codeigniter动态url搜索引擎友好?

示例:1

我的当前网址:选择名为“文章”的菜单后

http://localhost/lw_user/home_control/getMenu/52

预期网址:

    http://localhost/articles

示例:2 我的当前网址:在菜单“文章”下选择名为“thehindu”的子菜单后

http://localhost/lw_user/home_control/getPage/6

预期网址:

http://localhost/articles/thehindu

注意:这是动态 URL,内容正在从数据库中获取

【问题讨论】:

    标签: php mysql codeigniter codeigniter-url codeigniter-routing


    【解决方案1】:

    你所说的被称为slug

    那么,如何使用 slug?

    将举例说明:
    URL - http://www.example.com/products/apple-iphone-5S-16GB-brand-new/

    1) 假设您有一个产品页面,并且产品页面当然需要来自 URL 的一些数据来了解要显示的产品。
    2) 在我们使用从 URL 获取的 id 查询数据库之前。但现在我们将做同样的事情(查询我们的数据库),只需将 id 替换为 slug 就可以了!
    3)因此在您的数据库中添加一个名为 slug 的附加列。下面将是您更新的产品数据库结构(只是一个示例)。

    Columns                       Values
    
    id (int(11), PK)              1
    title (varchar(1000))         Apple iPhone 5S 16GB
    slug (varchar(1000))          apple-iphone-5S-16GB-brand-new
    price (varchar(15))           48000
    thumbnail (varchar(255))      apple-iphone-5S-16GB-brand-new.jpg
    description (text)            blah blah
    ...
    ...
    


    我之前也回答过 slug。检查它是否有帮助。
    How to remove params from url codeigniter
    Codeigniter - SEO Friendly URL Structure (Slug Implementation)

    【讨论】:

    • 运行上述代码时出现以下错误。遇到 PHP 错误 严重性:警告消息:Category::index() 缺少参数 1 文件名:controllers/category.php 行号:10 遇到 PHP 错误 严重性:通知消息:未定义变量:slug 文件名:控制器/类别.php 行号:12
    • 我给出的只是一个例子来解释。您必须根据您的要求运行您的想法来匹配它。
    【解决方案2】:

    这必须使用路由类来完成。

       $route['product/(:num)'] = "catalog/product_lookup_by_id/$1";
    

    我建议您查看用户指南以获取更多信息。

    https://ellislab.com/codeigniter/user-guide/general/routing.html

    【讨论】:

    • 这样做将使同一页面的 2 个链接处于活动状态。
    猜你喜欢
    • 2010-12-11
    • 2017-04-13
    • 2011-08-31
    • 2014-11-09
    • 2012-06-18
    • 2013-10-16
    • 2021-06-12
    • 1970-01-01
    • 2012-10-09
    相关资源
    最近更新 更多