I’m trying to understand how to properly use mod_rewrite. I have posts in my database that have a title and date. Right now I’m using mysite.com/post.php?id=3 to retrieve my post data and populate the page. I would like to have it like this: mysite.com/2011/03/27/my-title-like-so/. I’m guessing I’ll have to query my database for something other than the id, but i dont know. Can anyone help? Perhaps I’m over looking something very simple. So far I have it showing up like this: mysite.com/post/2/ , but that doesn’t help very much 😛
Thanks!
A common practice is to include both the ID and the title/date in the URL. That way it looks nice to search engines and you can still retrieve it efficiently by ID. As an example, look at the URL for this stackoverflow question.
Just a guess but that number in the URL is probably a generated ID. So you use the ID and just ignore the rest of the URL, e.g.: