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 www.domain.com/site1 www.domain.com/site2 According to the requirement, what I need is to behave as follows. For the site1 wwww.domain.com For site2 site2.domain.com 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.
Scott Gu has a great blog on URL Rewriting: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Hi there folks! is this post still open ? Salman 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. Salman
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: http://grey-tomb-stone-salman.biz/cargo/Account/Login.aspx now, after doing the steps explained by scot, my user can get to my login page by using this URL: http://grey-tomb-stone-salman.biz/cargo/Login/ (amazing!!) 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: http://grey-tomb-stone-salman.biz/cargo/Login/ 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) <configSections> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" /> </configSections> And I pasted the (hhtpModules) within the (system.web) section <httpModules> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" /> </httpModules> 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! <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" /> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer> 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, <rewriter> <rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" /> <rewrite url="~/Login/" to="~/Account/Login.aspx" /> </rewriter> 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 ~