web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

How To Rewrite A Sub Domain To A Directory In IIS

Ian Grieve Profile Picture Ian Grieve 22,784

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.

I need to offer apologies to whomever posted the solution I ended up using; I’ve dabbled with IIS before but I did a lot of searching, and trying of potential solutions, before I got a working one but I accidentally closed the browser and have no idea where the solution originated.

In the root of my domain.co.uk website I created a folder called subdomain (not really but making the example generic) and then added the following to the web.config file of the website;


<rewrite>
   <rules>
      <rule name="Rewrite sub-domain to dir" enabled="true">
         <match url="^(.*)$" />
         <conditions>
            <add input="{HTTP_HOST}" pattern="^subdomain\.domain\.co\.uk$" />
         </conditions>
         <action type="Rewrite" url="subdomain/{R:1}" />
      </rule>
   </rules>
</rewrite>

When a user visits http://subdomain.domain.co.uk the returned page is actually loaded from http://www.domain.co.uk/subdomain without the user being aware of this and they can navigate around the sub-domain as if it was it’s own self-contained website.

The only downside is if someone knows that subdomain is a sub-folder of domain then they could navigate to http://www.domain.co.uk/subdomain, but this can be handled with a little PHP code to redirect these people to a 404 page.


This was originally posted here.

Comments

*This post is locked for comments