How An URL Is Mapped To A Blog

Introduction

The manner in which Subtext maps a request to the final rendered output is worth describing in detail. Because Subtext supports multiple blogs in a single installation, it must map the incoming request URL to a specific blog instance. This document describes how this is done.

Anatomy of a Blog URL

If you’ve visited the host admin and edited a blog, you’ll notice that the URL to the blog is represented like so:

http://localhost/Subtext.Web/blog/default.aspx

This is the example of an URL when Subtext is configured to run in a Virtual Application in IIS.

In this case,

  • the Host Domain is “localhost
  • the Virtual Application is named “Subtext.Web”
  • and the Subfolder is named “blog

If IIS is configured to run Subtext in a webroot (most likely matching your production setup), then the URL would look more like:

http://example.com/blog/default.aspx

In which case,

  • the Host Domain is “localhost
  • there is no Virtual Application value
  • and the Subfolder is named “blog

In both the above examples, the blog is configured with a subfolder named “blog”, which is one common way many configure their blogs.

However, a blog can decide to be in the host domain root rather than a subfolder as in this URL.

http://example.com/default.aspx

In which case,

  • the Host Domain is “localhost
  • there is no Virtual Application value
  • and the Subfolder is blank

In the Host Admin tool, this is configured by editing the blog and setting the Subfolder field as in the image below:

Screen showing the editing of a blog in the Host Admin
Figure 1: Host Admin editing a blog's setting.

Incoming Request Parsing

When an incoming request comes in, Subtext first parses the host and looks up blogs (in table subtext_Config) that have a matching host value.

The query below is a simplified version of the one Subtext runs. (NOTE: The Application column corresponds to the Subfolder in the Host Admin. We did not change the column name yet.)

SELECT BlogId, Host, Application

FROM subtext_Config

If only one blog is found, it will assume that the record corresponds to the incoming request.

Multiple blogs

If multiple blogs match, then Subtext has a little bit more work to do. The results of such a request might look like so:

Screen showing blog records
Figure 2: Two blogs with the same host.

It then tries to parse out the subfolder of the incoming request by looking at the part after the host name.

Application Path

In the case of a blog installation within a virtual application, Subtext knows to look at the part of the URL after the application portion.

For example, on a local install of Subtext on Windows XP within the Subtext.Web virtual application, Subtext knows to look for the subfolder value after the Application value which is obtained via HttpContext.Current.Request.ApplicationPath.

Thus in the above example of an incoming request with the following URL:

http://localhost/Subtext.Web/blog/default.aspx

Subtext is able to figure out that the subfolder name is “blog” and is thus a request for the blog with the id of 1 and NOT the blog with an id of 2.

Subtext then parses the rest of the URL to figure out what page exactly is being requested. That’ll be covered in another topic.

Potential Blog Conflicts

Suppose Subtext receives an incoming request like so:

http://example.com/blog2/default.aspx

But Subtext has the following two blogs configured.

Screen showing two blog records, both with the same host name, but one with an empty subfolder name.
Figure 3: Two blogs with the same host, but one with no subfolder value.

At first glance, it seems obvious that we would select the blog with the id of 2. But we cannot be sure this is correct.

What if the first blog has a physical subfolder named “Blog2”. How can we be sure the request is not for a file in that folder?

Blogs With The Same Host Name Must Have A Subfolder Value

At the moment, Subtext does not allow for such a configuration. If two blogs have the same host name, they must have non empty distinct subfolder values.

Supports Blogs With different Host Names

Subtext supports any number of blogs with different host names. Two blogs with different host names do not have the restriction that both have non-empty Subfolder values.

As an example, here is a list of several blog records within a single installation of Subtext that are all valid.

Screen showing Multiple valid blogs within the same installation of Subtext.
Figure 4: Multiple valid blogs within the same installation of Subtext.

Notice that even though the first two blogs have the same subfolder value (in the application column), that is fine because they have different host names.

Likewise, it is fine that the haack.org blog does not have an application value defined because it is the only blog with the host name of “haack.org”.

Subtext Logo design by TurboMilk.