[英]Convert page title in URL to page id
I have taken advice from the following Stack Overflow article that numeric primary keys are searched faster than a string primary key in the MySQL database. 我从下面的Stack Overflow文章中获得了一些建议,即在MySQL数据库中,数字主键的搜索速度比字符串主键的搜索速度快。
Reference: Strings as Primary Keys in SQL Database 参考: 字符串作为SQL数据库中的主键
I have also taken into account the comments in this Stack Overflow article that id's in the URL of a page are not good for SEO. 我还考虑了此Stack Overflow文章中的评论,即页面URL中的id不适用于SEO。
Reference: Why is just an ID in the URL path a bad idea for SEO? 参考: 为什么仅URL路径中的ID对于SEO来说不是一个好主意?
Due to this, I have also put a great deal of effort into keeping my URL's clean to enhance SEO, but am keen to find out if anyone knows of a way to convert the title part of the URL below URL (this-is-an-example-page) into its numeric primary key id for searching. 因此,我还付出了很多努力来保持URL的整洁以增强SEO,但是我很想知道是否有人知道一种将URL标题部分转换为URL以下的方法(this-is-an -example-page)放入其数字主键ID进行搜索。
Example URL: http://www.example.com/this-is-an-example-page 范例网址: http : //www.example.com/this-is-an-example-page
I am using PHP on Apache server, with phpMyAdmin, and MySQL. 我在Apache服务器,phpMyAdmin和MySQL上使用PHP。
I have noticed that digg does the same sort of thing that I am trying to achieve. 我注意到,digg所做的事情与我试图实现的目标相同。 How would they do this?
他们将如何做?
The usual way is to have a separate column containing the textual ID and to create that from the article's name on create time. 通常的方法是拥有一个单独的列,其中包含文本ID,并在创建时根据文章名称进行创建。
Then you'd use mod_rewrite
to accept URLs in the form you describe, and pipe them to a script like index.php?id=this-is-an-example-page
. 然后,您将使用
mod_rewrite
接受您所描述的形式的URL,并将其通过管道传递至诸如index.php?id=this-is-an-example-page
类的脚本。 Then it's just a matter of querying for that new column, instead of the numeric ID (which should still exist internally). 然后,只需要查询该新列,而不是数字ID(应该仍在内部存在)即可。
For how to create a URL-friendly string from any title, see... mmm, I can't find a good question & answer on that right now. 有关如何从任何标题创建URL友好的字符串的信息,请参阅... mmm,我现在找不到关于此的很好的问题和答案。 This is an imperfect approach: Improve converting string to readable urls
这是一种不完善的方法: 改进将字符串转换为可读的url的方法
For the rewriting part, see How to create friendly URL in php? 对于重写部分,请参见如何在php中创建友好的URL?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.