URL Rewrite

Discussion in 'Site Programming, Development and Design' started by n8nt, Dec 18, 2009.

  1. I think I am dense. I just don't understand this URL Rewrite concept. I understand the article but it does not seem to help me do what I want to do.

    I have my main domain at the root. Call it www.main.com. It is an asp.net c# web site

    I created two folders under the root and named them web1 and web2.

    I then publish from Visual Studio two websites, again asp.net sites each with two pages called default.aspx and home.aspx.

    I create a domain pointer for each of these on my main website. I create one pointer called webone.com and another called webtwo.com.

    I create application starting points for each of them at (webone.com uses web1 and and webtwo.com uses web2.

    I've also set up the dns services to point webone.com and webtwo.com to ns1.Winhost.com, ns2.Winhost.com and ns3.Winhost.com.

    So what i want to do is use the URL ReWrite so that I can go to either of the sites and maybe run a blog engine on each site for that site only. And, I might want to use the Membership Role services of asp.net on these two sites.

    So I have set up the following rules in the web.config of the root domain:

    <rewrite>
    <rules>
    <rule name="Web One Rule">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="webone.com" />
    </conditions>
    <action type="Rewrite" url="web1/{R:0}" />
    </rule>
    <rule name="Web Two Rule">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="webtwo.com" />
    </conditions>
    <action type="Rewrite" url="web2/{R:0}" />
    </rule>
    </rules
    </rewrite>

    Then in each of the two web folders I create a rules secion like this in their web.confgs

    <rewrite>
    <rules>
    <rule name="WebOneFolder Rule" stopProcessing="false">
    <match url="(.*)" />
    <action type="Rewrite" url="/{R:0}" />
    <conditions logicalGrouping="MatchAny">
    </conditions>
    </rule>
    </rules>
    </rewrite>

    DOing this allows me to get to those web sites and and if I reference the pages in those websites with the ~/xxx everything seems to work.

    The only problem is that I see the name of the subfolder in the browser address bar. So, when I type www.webtwo.com I see http://www.webtwo.com/web2/default.aspx and when I click on a button on that page which redirects to ~/home.aspx I see in the browswer window:
    http://www.webtwo.com/web2/home.aspx.

    So is there any way to have it display only http://www/webtwo.com/home.aspx and http://www.webtwo.com/default.aspx?
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    You should use the URL Rewrite module in the IIS 7 manager rather then trying to hard code the root. It is much easier.
    Connect to our server using URL Rewrite Module. Click on 'Add Rules' and choose blank rule. For Requested URL: make sure you pick 'Match the pattern', and choose Regular Expressions.
    For the Pattern text type (.*).
    For the logical grouping use 'Match Any'. Add condions. Type [GTTP_HOST} for the condition input.
    for the patter typ ^webone\.com$
    On Action type choose Rewrite instead of Redirect.

    For the Rewrite URL: field type...
    \web2\[R:1}

    Repeat the steps as necessary for additional rules.
     

Share This Page