http-redirectiisdirectoryurlrewriter

IIS Rewrite instead of redirect from directory


How can I achieve this in IIS:

When I'll write in the browser: www.mydomain.com/mydirectory to go and point to subdomain.domain.com but the url to be like I've written it in my browser (eg.www.mydomain.com/mydirectory )


Solution

  • You can't rewrite a url to a different domain. You'd either have to do a redirect, or you can use an iframe to contain subdomain.domain.com inside of the page you have at www.mydomain.com/mydirectory.

    If you want to rewrite subdomain.domain.com to something like domain.com/subdomain, this would be possible since it is the same domain name, here's the rule in web.config:

    <rule name="RedirectSubdomain">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="(.*).domain.com" />
        </conditions>
        <action type="Rewrite" url="/{C:1}/{R:0}" />
    </rule>