IIS 7 and Above
URL Rewrite Module
Using Url rewrite to "delete" a folder
Last post Dec 05, 2017 07:58 AM by MrIISNet
Dec 04, 2017 11:22 PM|MrIISNet|LINK
Hello, I have a website that I need to use URL Rewrite to do certain things:
Server: Windows Sever 2012 R2
http://www.contoso.com/site1, default page is default1.aspx
Sub-website 2: http://www.contoso.com/site2, default
page is default2.aspx
#1: For both sub-websites, I want to remove the site path. That means, when accessing the two sub-websites, http://www.contoso.com/site1/default1.aspx will
become ttp://www.contoso.com/default1.aspx, and http://www.contoso.com/site2/default2.aspx will
#2: When accessing http://www.contoso.com, it will auto load the default page of sub-website 1. That means i want to make default1.aspx as the default page of the main website.
Thanks for the help!
Dec 05, 2017 06:28 AM|Yuk Ding|LINK
For #1, It is not difficult to hide the site path if it only have one sub-application. You only need to create a redirect rule
www.contoso.com/(.*) then rewrite the redirected URL back to www.contoso.com/site1/(.*). However I can't find any variable that could get where is it redirected from which means I can redirect
http://www.contoso.com/default1.aspx but how it is in certain whether http://www.contoso.com/default1.aspx
should be rewritten back to
For the second secenario, you could use this rule to rewrite the root to site1/default1.aspx:
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="site1/default1.aspx" appendQueryString="false" />
Dec 05, 2017 07:58 AM|MrIISNet|LINK
Hi, Yuk Ding,
Thank you so much for your solutions.
For #1, it is affirmative on your uncertainty. A developer in my firm told me that she needed to host multiple applications in different folders on a single IIS server while she only had one application ready at the moment. She wanted the website to display
no path/folder for all applications. I was trying to convince her not to do that, but just couldn't think of any reason or conflict in details. You just enlightened me. Thanks. Well, for now, it is fine because there is only one application. But I know what
is gonna happen when she has the second application ready. I am gonna smack her ass with the conflict you brought up.
For #2, i've been squeezing every cell of my brain to figure out this. I did it with default document feature, and it didn't work; I also did the rewrite (different rewrite method), and same result. Yours looks simple, and make much more sense.
1) for some rewrite/redirect rules, it does not even need enable="true" to be enabled, meaning that they don't even show up in the web.config file when using the GUI version to add rules.
2) What does stopProcessing="true" do here exactly? I know StopProcessing means no more subsequent rules will be processed. I have another rule to redirect HTTP to HTTPS. It is the first rule that I created using the GUI, and it has StopProcessing flag turned
on in the web.config file. Does that mean my other rules for #1 setup will not be processed? But when i test, my #1 works fine.
Thanks for your help again.