I’m creating a blog engine as a learning exercise and one particular problem has me stumped. I’m wondering how are blog posts created in say a blog engine such as WordPress? I’m thinking there are 2 ways you can do this:
1) Creating a new blog post called ‘testPost’ creates a new HTML page called http://www.myblog.com/testPost.html. So, for each new blog post you save a new HTML page to the server. This method seems inefficient. A blog can have hundreds of blog posts, which means you would have to create hundreds of HTML pages. I don’t think I want to use this method.
2) You have a generic blog post page whose data is rendered according to the post you are trying to access. For example, if I created ‘testPostOne’ the generic blog post page would be filled with testPostOne’s data and URL, if I created ‘testPostTwo’ then the generic page would render testPostTwo’s respective contents and so on.
But using this method brings its own problems. For example how would you link to a page that doesn’t actually exist? Linking to http://www.myblog.com/testPostOne.html would not work.
These are the two ways I could come up with to solve this problem. I’m not sure whether there are other options. Please feel free to recommend a better way of solving this problem if you know of one.
Basically, I want to be able to have a nicely formatted URL for each blog post without having to create a new HTML page on the server for each one.
EDIT: I might add that I’m using ASP.NET to do this so any methods available via this framework would be helpful
The basic idea would be to use a database. Each posting would be an entry in the DB, and you simply retrieve the data depending on the URL. For example,
http://www.myblog.com/posts.php?postid=1
or
http://www.myblog.com/posts.aspx?postid=1
You can then either use URL rewrite methods to retrieve the same post with a cleaner URL, or better yet a RESTful method to do the same task.