问题: 如何让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,内容是从数据库获取的
最佳答案
您所说的称为slug
。
那么,如何使用slug?
将举例说明:
网址 - http://www.example.com/products/apple-iphone-5S-16GB-brand-new/
1) 假设您有一个产品页面,当然产品页面需要来自 URL 的一些数据来了解要显示的产品。
2) 在我们使用从 URL 获取的 id 查询数据库之前。但现在我们将做同样的事情(查询我们的数据库),只需用 slug 替换 id 就可以了!
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 - 如何使codeigniter动态url搜索引擎友好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27331597/