Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two domains (domain1.com and domain2.com). Both of them use the same Windows hosting server with IIS7.

One of the domains is being called the "primary domain" by my hosting provider (GoDaddy) and it always points to the root folder that I was given.

For the other domain, I have created a virtual directory in IIS and pointed it there.

The folder structure is like this -

root/
--Default.aspx
--SomeFile.aspx
--domain2folder/
----Default.aspx
----Domain2SomeFile.aspx

So, if I type domain1.com, I see the regulakr Default.aspx. But if I type domain2.com, I am shown the contents of domain2folder as if it were a separate web application - I think that is what IIS virtual directory is meant for. Well and good.

But the problem is, when I type http://domain1.com/domain2folder, I see the domain2's website!

But I don't want that to be shown when I use the path like that from domain1. Only if they use domain2.com, user should be able to see those contents. How can I do that? Hope I am making sense.

Thanks.

share|improve this question
add comment

2 Answers

You can use URL Rewrite to prevent access based on the Host header or redirect to the right domain if desired: http://www.iis.net/download/URLRewrite

If your site is running in IIS 7 or above and your hoster has it installed you can just drop a web.config in your domain2folder with the following contents, it will redirect to the right domain if anybody tries to access it using the wrong domain:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="HostNameRule">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain2\.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://domain2.com/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
share|improve this answer
add comment

It seriously doesn't make sense to set it up this way.

You'd typically just set up domain2folder as the root of another web site.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.