URL Rewrite + Default Root Application

Discussion in 'General troubleshooting' started by arielsrv, Nov 19, 2011.

  1. Dear,
    I have a hosting which I need to redirect correctly two websites, subfolders in two separate sites running on ASP. NET MVC 3 and the physical layout is as follows.

    \ root
    \ site1
    \ site2

    Logically, from the registered domain hosting, you can access web sites as follows


    According to the requirement, what I need is to behave as follows.

    For the site1


    For site2


    I tried to write the rules necessary but I have not been able to accomplish the request properly in both cases, I wonder if anyone can help in the solution.
  2. Elshadriel

    Elshadriel Winhost Staff

  3. I've read, but still can not find the solution, please can you help me.
  4. Hi there folks!
    is this post still open ?


    cool! it is open!

    Hi once again, Ariel!

    Many thanks Elshadriel! Great link bro. I have been searching around for some easy
    beginner tips on this url-writing thingy. The Scots Blog page (above) is really cool, I am actually doing some primary tests with the sample code and looks like it is working.

    Ariel, not sure if you got your thingy fixed by now, i know it is an old post from 2011..I will do another few tests with my webapp and make sure I got my "scenario" working, then I will post what I did for you Ariel, may be it will help.

    alright..catch up with you folks in a bit.

  5. hi once again Arial,
    mind you this is an old post, it is Thursday Jurene 28th here in Bahrain (2012 that ). I hope maybe my findings after reading Elshadriel’s (the Winhost staff lad) (and thanks Elshadriel), I hope my findings would help Arial (the originator of this post or maybe someone else who has been trying to figure out what this URL-rewriting thingy like my self)..so here what I have tried so far and it worked.
    Differently than Arial’s case, but I am sure it can be accomplished as well, with the URLWriter.Net module suggested by the scot (schot’s blog – the link above posted by Elshadriels), I don’t have a scenario of a domain and a sub-domain such as Ariel, however so far I am working on one domain and (I am still haven’t started playing with subs yet ---- I am still a newbie on Winhost ! )
    For the record, I am have used the 3rd approach suggested by Scot’s blog. (which is using the new features of IIS 7, and I have benifited from the sample code given out on scot’s blog too. So all the stuff I have tried and worked out perfectly well for me, are all from scot’s blog post.
    What I found is, personally, I had the entire understanding of the url-rewrite kinda wrong, instead what I have learnt and tried is, to have my web application handle incoming requests (incoming URL requests, those which are cleanly and beautifully made) have my application (convert them back) to their actual real “URLS” internally so that my “response.redirect” code will take my user to the proper page. (Again, I am explaining all this based on my scenario). right, enough of the talk, this is my application and the url for my login page:
    now, after doing the steps explained by scot, my user can get to my login page by using this URL:
    That’s not it (only). ! this means, within my response.redirect code in my Code Behind, I no longer have to say this:
    Response.Redirect(“~/Account/Login.aspx”, True)
    Instead, I will replace it with this:
    Response.Redirect(“~/Login/”, True)
    And this is exactly what will appear on my users browsers’ Address Bar:

    again, this is all basics, this is what I have tried so far, I mean someone has to start somewhere, right! So I feel this is a cool start, at least for me, I am really glad this thing works.
    Now, briefly, and quickly, all I did is the following (I didn’t even have to bother my self with the details and meanings really!)
    First thing, I downloaded the sample code from scot’s page, and in particular I have downloaded this one: http://www.scottgu.com/blogposts/urlrewrite/UrlRewrite_HttpModule2.zip

    And simply, I copied the dll file in the BIN folder into my computer, and then added a reference to it in my ASP.NET Web application (mind you, I am working with .net Framework 4. and VB code – I am still a C# newbie )
    Then, I copied those four sections in my web.config (my applications’ web. Config, and mind you I am hosting it on my Winhost iss (which is version 7 of course).
    So I pasted this section (configSection) which goes within the (configuration)

    <section name="rewriter"
    type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />


    And I pasted the (hhtpModules) within the (system.web) section
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />

    Third section I pasted is (system.webserver) section (mind you this section is outside the system.web, of course within the parent section (configuration) – This was confusing for me too at the start!

    <modules runAllManagedModulesForAllRequests="true">
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />

    <validation validateIntegratedModeConfiguration="false" />


    Finally, this is where the magic happens (rewriter) section, mind you this is a section on its own, it is only within the parent (Configuration) and not under any other sub section,

    <rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" />
    <rewrite url="~/Login/" to="~/Account/Login.aspx" />


    You see the first line is from the sample code, and the one bellow it is the one I was talking about above (the login.aspx).
    If I am not mistaken, this is the section where they call it rules, or rewriting rules (correct me if I am wrong Elshadriel!
    Well, I guess that’s it.
    I wanted to share this in case another newbie such as my self might come across and find this somehow useful!
    Thanks once again folks
    Thanks once again Elshadriel..and Good luck Ariel!
    ~Salman ~
    Last edited by a moderator: Oct 14, 2015

Share This Page