php - How do I create permalinks that are database driven?


I'm looking for a way to translate


I'm ok with doing some sort of RewriteRule with Mod Rewrite, but I'm not sure how to do it exactly. My pages are coded in PHP pulling from a MySQL database.

Hopefully someone can tell me how to do this!

I know there are others looking for a similar answer.

Thanks again!





You're going to need a rewrite rule in your web server configuration to translate e.g./123 to/index.php?id=123 - it's not a PHP issue per se.




All the below stuff can be implemented with apache rewrites. You can find a ton of tutorials and documentation on how to do this.

In order to make permalinks look nice and SEO friendly, you can follow the pattern as a link for the article entitled "How to do stuff". However if your site will get many articles, things will slow down a little bit because of text search in the database (that will be a hard to achieve level, but let's talk hypothetical).

As a result I'd recommend using the phpBB pattern where 12345 is the id of the pattern in the database (or any other id that's fast enough to select from db). That's not all. There 'should' be one more verification step, where the text from the URL, is compared with the title of selected article, and an eventual redirect to the correct URL will be done.

People are also looking for solutions to the problem: PHP: Timestamp difference incorrect


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.