简体   繁体   中英

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.

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM