What is the most efficient way to realize php-driven permalinks?
Basically I want to reduce the database accesses to a minimum.
What is the best way to redirect to an id stored in the database?
What is the most efficient way to realize php-driven permalinks?
Basically I want to reduce the database accesses to a minimum.
What is the best way to redirect to an id stored in the database?
Use a simple URL-to-ID map to retrieve the ID based on the URL:
+----------+----+
| URL path | ID |
+----------+----+
| /foo | 1 |
| /bar | 2 |
| /bar/baz | 3 |
| … | … |
+----------+----+
You can use a db ID based url like SO does:
http://stackoverflow.com/questions/1265061/efficient-way-to-realize-permalinks-in-php
or
http://stackoverflow.com/questions/1265061
both go to the same place.
This is usually done through some sort of mod_rewrite redirect to your php file from a .htaccess.
RewriteRule ^/questions/([0-9]+)/?.*$ /questions.php?id=$1
The rewrite rule throws away everything after the ID - so you could even go to
http://stackoverflow.com/questions/1265061/not-the-questions-title-anymore
And you still reach your destination. You'll want to add the "title slugs" to the actual URL being 'linked' when you generate the links in php - it will improve your Search Engine Friendliness...