Question: I have a website with a database of 2,4 million entries. Now I want to use mod\_rewrite to produce clear URLs like example.com/this-is-a-beautiful-url. To recognize which URL belongs to which page I want to build a URL-table which refers to the website's content. Like "this-url-example" belongs to the post with the ID 123. 
Now 2 friends are telling me 2 different ways to build this table and I don't know which one is the best.

1. Advice: "Make a MD5 hash of the URLs and save them in a binary field with an index".
2. Advice: "Simply save the urls in plain text and put an index on it".

Which method would provide faster select-queries? Do you have another advice? Thanks!

Answer: 
Go for a compromise, have urls as
sitename.com/12345/clean-url-format

You have both keywords in a readable URL and the identified which you can use to fetch the row by the primary key for speed.

It would be reasonable to redirect urls without the text part to the canonical version with it.
I would not use either mysql or md5 hashing. Instead, use a key-value store such as [dbm](https://en.wikipedia.org/wiki/dbm) or [leveldb](http://leveldb.org/). If you are using Apache's `mod_rewrite`, it has a feature, [RewriteMap](http://httpd.apache.org/docs/current/rewrite/rewritemap.html) that can read the keys and values directly from a dbm db, or by calling an external program. The type can be `sdbm`, [`gdbm`](http://www.gnu.org.ua/software/gdbm/), `ndbm` or `db` ([Berkeley DB](https://en.wikipedia.org/wiki/Berkeley_DB)), and apache includes a program, [httxt2dbm](http://httpd.apache.org/docs/current/programs/httxt2dbm.html), to create the database. If you do want to use MySQL, RewriteMap can do that as well with the dbd option, and [mod\_dbd](http://httpd.apache.org/docs/current/mod/mod_dbd.html). Performance-wise, using a hash index on MySQL should be similar to Berkley DB.