-2

I use iis 8, mvc 5, c#.

I want url's like subdomain.site.ru/path/to/file goes to ./subdomain/path/to/file (if file exists), by internal redirect. And I want url's like subdomain.site.ru/Controller/Action goes to Action of my Controller.

First, i bind all subdomains to my site in iis manager. What should i do next? I've found the article http://msdn.microsoft.com/en-us/library/ms972974.aspx, but I think it should be easier way to do it. Should i use routes.MapRoute() or URLRewriter or i need to extend BaseModuleRewriter?

UPD

it's not a dublicate question, because additionally I want to rewrite url and then check if file exists

UPD 2

I ve installed url rewrite, now i have something like this:

    <rule name="Subdomain" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="Subdomain{REQUEST_URI}" matchType="IsFile" />
        <add input="{HTTP_HOST}" pattern="^subdomain.site.ru$" />
      </conditions>
      <action type="Rewrite" url="http://site.ru/Subdomain/{R:0}" />
    </rule>

It doesn't work - error 404. 1) Please help me, what is wrong? 2) And how to change "Subdomain" to any subdomain? 3) Is there a method of debugging-by-line of url rewrite config?

UPD 3

Solution:

    <rule name="Sub" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{DOCUMENT_ROOT}/Sub{PATH_INFO}" matchType="IsFile"  />
        <add input="{HTTP_HOST}" pattern="^sub.site.ru$" />
      </conditions>
      <action type="Rewrite" url="/Sub{PATH_INFO}" />
    </rule>
Dmitry
  • 581
  • 1
  • 4
  • 15

1 Answers1

0

Solution:

<rule name="Sub" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{DOCUMENT_ROOT}/Sub{PATH_INFO}" matchType="IsFile"  />
    <add input="{HTTP_HOST}" pattern="^sub.site.ru$" />
  </conditions>
  <action type="Rewrite" url="/Sub{PATH_INFO}" />
</rule>
Dmitry
  • 581
  • 1
  • 4
  • 15