How to rewrite a URL as a subdomain in asp.net without actually creating a subdomain on the server

I hope this is not the first time I ask this question on SO.

I have URLs on my site that use values query string For example: http://foo.com/xyzPage.aspx?barvalue=yehaa

to

http://yehaa.foo.com/

Please suggest how this can be done without actually creating subdomains on the server ..

I have IIS 7.5 installed on the server and Asp.net 4.0 .

Many thanks

+5
source share
1 answer

EDIT by following our comments:

http://foo.com/xyzPage.aspx?barvalue=yehaa http://yehaa.foo.com/, :

<rules>
    <rule name="Rewrite subdomains">
        <match url="^/?$" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(.+)\.foo\.com$" />
        </conditions>
        <action type="Rewrite" url="http://foo.com?barvalue={C:1}" />
    </rule>
</rules>

url / - foo.com, http://foo.com?barvalue={C:1}, {C:1} - , foo.com.

, http://foo.com?barvalue={C:1}, .


Rewrite IIS, web.config:

<rewrite>
    <rules>
        <rule name="Redirect to Subdomains" stopProcessing="true">
            <match url="^xyzPage.aspx$" />
            <conditions>
                <add input="{QUERY_STRING}" pattern="^barvalue=(.+)$" />
            </conditions>
            <action type="Redirect" url="http://{C:1}.{HTTP_HOST}" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>

, url xyzPage.aspx ( ).
, querystring barvalue ( ), .
2 , Redirect http://barvalue.original.host.

Rewrite, , , , type="Redirect" type="Rewrite".

. , , - Rewrite .

+12

All Articles