0

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?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Richy
  • 69
  • 2
  • 9

1 Answers1

0

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?

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Cheers. Would'nt you be searching the table for a string then though? Resulting in slower search results and page loads? – Richy Sep 08 '13 at 14:29
  • @Richy meh, it's unlikely to even be an issue unless you have to handle hundreds or thousands of requests per second. If the column is properly indexed, the difference will be minimal. Plus it's the only way to do this – Pekka Sep 08 '13 at 14:34