搜索引擎友好的长期语法 [英] SEO friendly term syntax

查看:144
本文介绍了搜索引擎友好的长期语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个脚本,将选择从URL的一个术语,并从我的数据库基础上的长期拉正确的数据。

I am writing a script that will pick a term from URL and pull the right data from my db based on that term.

到目前为止,我还添加了一行到我的.htaccess文件,将重写我的网址搜索引擎友好的格式,是这样的:

So far I have added a line to my .htaccess file that will rewrite my URL into SEO friendly format, something like:

http://mydomain.com/catalogue/some-item-name

在实际的PHP页面我抢这个变量,带破折号

On the actual PHP page I grab that variable, strip dashes

$item= str_replace('-', ' ', $_GET['item']);

和符合我的网页上的项目,以隐藏列表拉匹配的jQuery。

and match the item to the hidden list on my page to pull the match with jQuery.

一切工作正常,除非我其实已经在项目名称破折号。我的脚本删除所有破折号。我应该:

Everything works fine, unless I actually have a dash in the item name. My script removes all dashes. Shall I:

  1. 替换实际的横线成别的东西?
  2. 找到一种方式剥离只是一个单一的几许?

如果我是拉期限从DB我可能已经使用的 WHERE项目,如%$项%,而是因为我必须匹配精确的术语alredy present在我的HTML code,我有点卡住。

If i was pulling the term from db I could've used WHERE item LIKE "% $item %" but because I have to match to exact term alredy present in my HTML code, I'm kinda stuck.

感谢。

推荐答案

我们使用一个系统,我们检查传入的URI针对数据库,看看那里发送给用户。这样,我们就可以完全从系统内部(例如ID)的分离的URI。

We use a system where we check the incoming URI against the database and see where to send the user. This way, we can completely detach the URI from the system internals (such as IDs).

我们匹配数据库中的 URI 外地传入的URI,并从正确的类(控制器)或重定向加载正确的功能。它还可以将参数传递给函数的选项。

We match the incoming URI against the uri field in the database and load the correct function from the correct class (controller) or redirects. It also has the option to send parameters to the function.

让我展示通过例子

+---------+---------+----------+----------+--------+
| uri     | class   | function | new_uri  | vars   |
+---------+---------+----------+----------+--------+
| faq     | support | faq      |          |        |
+---------+---------+----------+----------+--------+
| sandwich| content | news     |          | 1      |
+---------+---------+----------+----------+--------+
| banana  |         |          | sandwich |        |
+---------+---------+----------+----------+--------+

案例1: 用户请求test.com/faq的URI路由器发现的URI ='常见问题解答'匹配,并告诉系统diplay任何常见问题解答()在支持类或控制器显示器。

Case 1: The user requests test.com/faq, the URI router finds a match on uri = 'faq' and tells the system to diplay whatever faq() in the support class or controller displays.

案例2: test.com/sandwich这是一个新闻故事ID为1的快捷方式的用户请求于是URI路由器发送一个呼叫新闻()在内容类我们可以从一个变量检索ID喜欢 $ _ GET ['乏'] [0]

Case 2: The user requests test.com/sandwich which is a shortcut for a news story with the ID 1. So the URI router sends a call to news() in the content class and we can retrieve the id 1 from a variable like $_GET['vars'][0].

案例3: 用户请求test.com/banana,这已被移动到test.com/sandwich~~V因为我们没有在香蕉工业了。因此,URI路由器礼貌地发送301将用户重定向到正确的位置。

Case 3: The user requests test.com/banana, which has been moved to test.com/sandwich since we are not in the banana industry anymore. So the URI router politely sends a 301 and redirects the user to the correct place.

该方法有多种方式扩大,例如允许通配符的URI领域等希望它可以对一些价值你。

This method has many ways to expand, e.g. by allowing wildcards in the uri field etc. Hope it can be of some value to you too.

这篇关于搜索引擎友好的长期语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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