IIS Rewrite Rule for Redirect to Directory

Microsoft Dynamics GPThe web hosat I am currently with allows multiple domains, but only 6 websites; this means I have to be a little creative sometimes when creating additional sites.

I actually have a lot more than six websites being hosted on my account, due to a mix of WordPress MU and redirects to folders.

The redirect is done using an IIS rewrite rule. As I may be moving web host soon, I’m posting this so that I have easy access should I need.

This code goes in the rewrite section of the web.config file:

Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
		<rule name="Rewrite subdomain.azurecurve.co.uk subdomain to dir" enabled="true">
			<match url="^(.*)$" />
				<add input="{HTTP_HOST}" pattern="^subdomain\.azurecurve\.co\.uk$" />
			<action type="Rewrite" url="_subdomain.azurecurve.co.uk/{R:1}" />
		<rule name="subdomain.azurecurve* wordpress" patternSyntax="Wildcard">
			<match url="*subdomain.azurecurve*" />
				<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
				<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
			<action type="Rewrite" url="_subdomain.azurecurve.co.uk/index.php" />

The second rule is, I believe, required specifically for redirects for WordPress sites, the majority of which my rewrites are for.

How To Rewrite A Sub Domain To A Directory In IIS

When I signed up with my current web host the deal was limited to six domains and unlimited websites; a restriction I figured I could live within as a lot of what I intended to do would be in sub-domains and the unlimited websites allowed me to have each sub-domain in an individual website.

However, since I signed up they have, without giving any form of notification, changed the deal so it is now unlimited domains and only six websites. I’m currently in a position that I have five domains and twelve websites without the ability to create another website; the control panel shows me as having 12 of 6 websites. The only positive is that they have not, as yet, required me to trim down the number of websites I have.

I therefore spent a little time yesterday looking for a resolution to this problem. Continue reading “How To Rewrite A Sub Domain To A Directory In IIS”