CodeIgniter:SEO友好的URL [英] CodeIgniter: SEO friendly URLs

查看:165
本文介绍了CodeIgniter:SEO友好的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CodeIgniter开发一个电子商务网站。

I'm developing an e-commerce site using CodeIgniter. What are the general strategies used in order to create SEO friendly URLs?

说我有一个 id 的产品,索尼电视中的 123 和产品名称 32。我只需执行以下操作:

Say I have a product with an id of 123 and a product name of 32 in Sony TV. Do I just do the following:

http://www.domain.com/product/123/32-in-sony-tv/

含义,我有2个URI段。第一个用于标识实际产品。第二个是被应用程序忽略的(虽然内部链接,sitemap.xml等都以其SEO友好形式引用产品)。

Meaning, I have 2 URI segments. The first is used to identify the actual product. The second is just ignored by the application (though internal links, sitemap.xml, etc. all refer to the product in its SEO friendly form).

建议? p>

Suggestions?

推荐答案

我已经解决了这个具体问题与CodeIgniter的URI路由和非常成功。

I have tackled this specific issue a much different way with CodeIgniter's URI Routing and with great success.

创建新产品时,应将连字符名称(32-in-sony-tv)存储在数据库的产品表中的唯一索引字段中。创建连字符名称的函数应检查名称是否已被使用,并添加-1, - 2,-3等等,直到找到一个字符串未使用(例如:32-in-sony -tv-4)。

When you create a new product, you should store the hyphenated name (32-in-sony-tv) in a unique, indexed, field in your products table of your database. The function that creates the hyphenated name should check if the name is already used and add "-1","-2", "-3" and so on until it finds a string not being used (ex: 32-in-sony-tv-4).

application / config / routes.php 文件中添加:

$route['product/(:any)'] = "catalog/lookup_by_hyphenated_name/$1";

这将重新路由 http://www.domain的请求。 com / product / 32-in-sony-tv http://www.domain.com/catalog/lookup_by_hyphenated_name/32-in-sony-tv 在幕后,并允许各种灵活性。

This would re-route requests for http://www.domain.com/product/32-in-sony-tv to http://www.domain.com/catalog/lookup_by_hyphenated_name/32-in-sony-tv behind the scenes and allow for all sorts of flexibility.

这篇关于CodeIgniter:SEO友好的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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