I-M-JM
I-M-JM

Reputation: 15950

web.config rule for sub-directory to sub-domain redirection

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.

Upvotes: 2

Views: 3226

Answers (1)

David Silva Smith
David Silva Smith

Reputation: 11706

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>

Upvotes: 2

Related Questions