How does a blog engine create blog posts?

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 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.

Read More

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

Related posts

Leave a Reply

5 comments

  1. You’ll need to make a dynamic page in, say, PHP that reads data from a database for the post content. If you want pretty URLs with your page, then you’ll want to look into something like mod_rewrite for rewriting the URLs.

  2. Personally, I use the Apache mod_rewrite. So when you have an URL like:

    http://myblog.com/archives/my_very_first_post,

    You can make a rewrite rule like this:

    RewriteEngine on
    RewriteRule ^archives/(.*)$ myblog.php?post=$1
    

    Apache interprets “my_very_first_post” as a post ID and feeds it to a PHP script that handles the ID. The script then Fetches the post from database and displays it.

    I believe this is the most common approach.