如何从 url codeigniter 中删除参数 [英] How to remove params from url codeigniter

查看:24
本文介绍了如何从 url codeigniter 中删除参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的网址:

<块引用>

http://domain/sentencijos/autoriai/429/marselis-prustas,

其中 sentencijos 是控制器,autoriai 是方法,429(param) 是 marselis prustas ID.我想删除此参数 (ID) 但不知道如何删除.

完整网址应如下所示:

<块引用>

http://domain/sentencijos/autoriai/marselis-prustas

有人可以帮我吗?谢谢

解决方案

将 URL 中的 slug 替换为 id.

它是这样工作的:

1) 我假设这里有一个产品网站流程.
2) 对于特定的产品页面,显示产品详细信息需要来自 URL 的一些数据(可以是任何product idproduct slug 等).
3) 在 URL 中使用 product ids 不被认为是一种好的做法.它既不SEO 友好用户友好.以下是使用 product id

的 URL 示例<块引用>

http://www.example.com/products/123/

4) 因此,替代方法是所谓的product slug
5) slug (语义 URL 或固定链接) 基本上是一个有意义的、seo 友好的、人类可读的关键字序列,由连字符(或下划线)分隔.以下是使用 product slug

的 URL 示例<块引用>

http://www.example.com/products/apple-iphone-5S-16GB-brand-new/

在这里,apple-iphone-5S-16GB-brand-new 是一个蛞蝓.

从这个页面的网址也可以了解到,

<块引用>

http://stackoverflow.com/questions/24800780/how-to-remove-params-from-url-codeigniter

哪里,
   24800780 = 这是唯一的 question_id
   how-to-remove-params-from-url-codeigniter = 这是根据您的 questionslug/p>


如何使用 slug?

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

id |标题 |蛞蝓价格|缩略图|描述


在您的代码中:

假设这是您的网址,

http://domain/sentencijos/autoriai/marselis-prustas

并且这个 marselis-prustas 可能是您的 slug 值,您的控制器函数将接收它并传递给模型,该模型逐渐使用它来查询数据库.
为此,您必须创建一个新列(如上所述),其值应为 marselis-prustas 和其他 slugs.


URL 中 slug 的优点:

1) SEO 友好
2) 用户友好
3) 干净且有语义的 URL

I have url like this :

http://domain/sentencijos/autoriai/429/marselis-prustas,

where sentencijos is a controller, autoriai is a method, 429(param) is marselis prustas ID. I want to remove this param (ID) but don't know how.

Full url should look like this:

http://domain/sentencijos/autoriai/marselis-prustas

Can someone help me? Thanks

解决方案

Replace slug with id in your URLs.

This is how it works:

1) I'm assuming here a product website flow.
2) For a particular product page, displaying the product details need some data from the URL (it can be anything product id, product slug, etc).
3) Using product ids in URLs is not considered a good practice. Its neither SEO friendly nor User friendly. Below is the example of an URL using product id,

http://www.example.com/products/123/

4) Hence, an alternative to this is what is called as product slug
5) A slug (semantic URL or Permalinks) is basically a meaningful, seo friendly, human readable sequence of keywords separated by hyphens (or underscores). Below is the example of an URL using product slug,

http://www.example.com/products/apple-iphone-5S-16GB-brand-new/

Here, apple-iphone-5S-16GB-brand-new is a slug.

You can also understand from the URL of this page,

http://stackoverflow.com/questions/24800780/how-to-remove-params-from-url-codeigniter

where,
   24800780 = this is the unique question_id
   how-to-remove-params-from-url-codeigniter = this is the slug made from your question


How to use slug?

1) Ofcourse your product page needs some data from URL to understand which product to display.
2) Before we were querying our database using the id we are getting from the URL. But now we'll do the same thing (querying our database) just replacing id with slug and thats it!
3) Hence adding an additional column in your database named slug. Below will be your updated product database structure.

id  |  title  |  slug  |  price  |  thumbnail  |  description


In your code:

Assuming this to be your URL,

http://domain/sentencijos/autoriai/marselis-prustas

and this marselis-prustas might be your slug value which your controller function will receive and pass to the model which gradually use this to query the database.
For this, you have to create a new column (as explained above) which should have the value marselis-prustas and also other slugs.


Advantages of slug in URLs:

1) SEO Friendly
2) User Friendly
3) Clean and semantic URLs

这篇关于如何从 url codeigniter 中删除参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆