php - Not sure how to get mod_rewrite to write to a certain format -
I'm trying to understand how to properly use mod_rewrite. I have posts in my database which have a title and date. Right now I am using mysite.com/post.php?id=3 to recover my post data and am populating the page. I like this: mysite.com/2011/03/27/my-title-like-so/ I'm guessing that for anything other than ID, I have to ask my database, but I do not know. Can anyone help? Maybe I'm seeing something very simple so far I have shown it like this: mysite.com/post/2/, but it does not help too much: p
Thanks!
Including both ID and title / date in the URL is a common practice. This way it looks good for search engines and you can still recover it efficiently by ID. As an example, look at the URL for this stack overflow question. Just an estimate, but if the number in the URL is probably a generated ID then you use the ID and just ignore the rest of the URL like: http://stackoverflow.com/questions/5451267/not-sure-how-to-get-mod-rewrite-to-write-to-a-certain-format < Code> rewrite rule / (\ d +) question.php? Id = $ 1
Comments
Post a Comment