2

I was already running a sub-website under following path

http://example.com/sub-site/

Now, I have created a sub-domain

http://sub-site.example.com/

Require "web.config" file code that can do 301 in following way

Request                                     Redirect to
--------------------------------------------------------------------------
http://example.com/sub-site/                http://sub-site.example.com/
http://example.com/sub-site/page-1.html     http://sub-site.example.com/page-1.html
http://example.com/sub-site/page-2.html     http://sub-site.example.com/page-2.html
.
.
.
http://example.com/sub-site/page-N.html     http://sub-site.example.com/page-N.html

Basically, rule should be written in such a way that "http://example.com/sub-site/" is changed to "http://sub-site.example.com/" in request, and browser should be redirected to newer location.

David Silva Smith
  • 11,498
  • 11
  • 67
  • 91
I-M-JM
  • 15,732
  • 26
  • 77
  • 103

1 Answers1

2

This should work.

    <rewrite>
        <rules>
            <rule name="redirect to subdomain" stopProcessing="true">
                <match url="(.*)" />
                <action type="Redirect" url="http://sub-site./{R:1}" appendQueryString="false" />
                <conditions>
                </conditions>
            </rule>
        </rules>
    </rewrite>
David Silva Smith
  • 11,498
  • 11
  • 67
  • 91