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. http://stackoverflow.com/questions/5451267/not-sure-how-to-get-mod-rewrite-to-write-to-a-certain-format

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:

 < Code> rewrite rule / (\ d +) question.php? Id = $ 1    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -