Using Url Rewriting to Host Multiple Apps/Blogs


When you need different applications or blogs to have separate domain names, you will probably need a hosting at accepts multiple applications. But sometimes, you are fine with a single domain, but do want to host multiple blogs under it. For instance, I have a main blog, a separate fitness blog, a couple of MVC3 web applications, all running under the same domain, When I tried hosting all these (2-3 MVC3 Aps, 2 wordpress blogs) on a single application hosting site, it caused some problems. When I looked around for solutions, I found out that a lot of people are having the same issue, especially when trying to host multiple wordpress blogs in their site. There are a couple of solutions, but the simplest and most efficient one, is a URL rewrite.

I will base my example assuming that you have a .NET hosting. Things might be a bit different for a Linux hosting.

So my issue was that I had everything on… going to the blog. But at the same time, I also wanted to work with a calorie tracking MVC3 web app I was building. So for that to work, all you need is a few lines of rules in the root of your main “www” hosting folder inside the web.config file. You could also use the IIS manager to do this – which has a nice GUI to help you build more complex rules. You can Here is how one would like:

<?xml version="1.0" encoding="UTF-8"?>
		<rule name="wordpress" patternSyntax="ECMAScript" stopProcessing="true">
			<match url="^(?!(?:calorified|eatoutadvocate|fitness)/)(.*)$" ignoreCase="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
			<action type="Rewrite" url="index.php" />

And you can add as many matches or ignores you would wish to add. This can even be used to change extensions to look more like RESTful URLs, although there are some performance issues with that. Oh well, at least for now, you can be on your way hosting as many apps as you’d like under a single app hosting plan, with 2 minutes of URL rewriting.

**One note for multiple wordpress blogs though: If your hosting plan only supports one instance of MySQL, then you will have to edit the config.php of your wordpress installation files and change the database prefix to something other than what you have for your existing blogs so that it does not interfere with them. If not, wordpress will refuse to install indicating that another version is already installed.