doushaqing7080 2013-09-08 14:19
浏览 46
已采纳

将URL中的页面标题转换为页面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.

Reference: Strings as Primary Keys in SQL Database

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.

Reference: Why is just an ID in the URL path a bad idea for 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.

Example URL: http://www.example.com/this-is-an-example-page

I am using PHP on Apache server, with phpMyAdmin, and MySQL.

I have noticed that digg does the same sort of thing that I am trying to achieve. How would they do this?

  • 写回答

1条回答 默认 最新

  • dongzhou1901 2013-09-08 14:22
    关注

    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.

    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. Then it's just a matter of querying for that new column, instead of the numeric ID (which should still exist internally).

    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. This is an imperfect approach: Improve converting string to readable urls

    For the rewriting part, see How to create friendly URL in php?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用