Struggling with IIS URL Rewrite 2.0

When it comes to the URL rewrite rules, I'm a bit of a basket case.  I need to do the following:

I have employees going to http://myapp.server.com

I need them to wind-up at http://myapp.server.com/appsubdirectory

I have tried several things, but I can't seem to get the pattern matching correct.  Help.
LVL 5
Eric GreeneDirector of TechnologyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LajuanTaylorCommented:
@ccbbc_cs - Can you please post the URL rewrite rules that you've tried?

Also, are these requests going straight to the IIS App server, or are they hitting an IIS reverse proxy first?
Eric GreeneDirector of TechnologyAuthor Commented:
Here are the results of the two I currently have.  Until the static IP is installed, I have to live with a temporary dynamic DNS style account (hence the two rules).

<rewrite>
            <rules>
                <rule name="WS Static IP" patternSyntax="ECMAScript">
                    <match url="^(app.mydomain.com)$" />
                    <action type="Rewrite" url="{HTTP_HOST}/application" logRewrittenUrl="true" />
                </rule>
                <rule name="WS Dynamic IP" patternSyntax="ECMAScript">
                    <match url="^(dyniphost.host.com)$" />
                    <action type="Rewrite" url="{HTTP_HOST}/WS2015" />
                </rule>
            </rules>
        </rewrite>

Open in new window

LajuanTaylorCommented:
@ccbbc_cs - Thanks.

Just confirming... Do you need the URLs to be rewritten to different  directories?
{HTTP_HOST}/application
{HTTP_HOST}/WS2015

This is what the URL Rewrite snippet is indicating. However, your initial question asks to rewrite all requests going to: http://myapp.server.com to a sub directory - http://myapp.server.com/appsubdirectory.

I want to make sure that we construct the correct incoming pattern match URL and the appropriate rewrite output to solve your problem.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Eric GreeneDirector of TechnologyAuthor Commented:
No, I just didn't clean-up one of the directory mentions.
Eric GreeneDirector of TechnologyAuthor Commented:
Assume they are both /application
LajuanTaylorCommented:
@ccbbc_cs - The following works on IIS 7.5, Windows 64 Bit OS... I placed the following in my web.config file for the "wwwroot" folder. All requests coming into "http://localhost" are redirected to: http://localhost/application.

This should work regardless of server IP

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>  
				<rule name="Redirect root to subdirectory" stopProcessing="true">
					<match url="^$" />
					<action type="Redirect" url="{R:0}/application" />
				</rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eric GreeneDirector of TechnologyAuthor Commented:
Thank you Lajuan.  My problem is that other sites will need to be available as well, so catching ALL incoming URLs and redirecting them won't work for me.  I need to be able to redirect for the two specific domains  "app.mydomain.com" and "dyniphost.host.com"

Other host headers will be hosted that I won't want to redirect.
LajuanTaylorCommented:
@ccbbc_cs - Okay.
So do you have three sites defined in IIS?
Site 1 - Default Site (myapp.server.com)
Site 2 - app.mydomain.com
Site 3 - dyniphost.host.com

I'm trying to determine what your users primary entry point will be. For example:
myapp.server.com - display all general content
myapp.server.com/application1 - redirect to: app.mydomain.com
myapp.server.com/application2 - redirect to: dyniphost.host.com
Eric GreeneDirector of TechnologyAuthor Commented:
I have one site defined with multiple host header bindings.  The site is hosted on a Windows server 2012 server.

Working with the URLS values in the rule, here is the explanation that I hope makes sense:

app.mydomain.com is for those who access the site from the inside for now.  The static IP and corresponding DNS A record are not established yet.  So, this URL only works on the inside where our internal DNS server catches it.

dyniphost.host.com is for those who are not in the building on the network.  It is a generic host name with a company that provides dynamic IPS services (because our static is not in place yet).  However, the need to access is immediate, so I need to trap this one too.

If the user types app.mydomain.com I want IIS to append /application to the end of that URL.

If the user types sunup host.host.com I want IIS to append /application to the end of that URL.

Both URLs lead to the same IIS site.
Eric GreeneDirector of TechnologyAuthor Commented:
I hate autocorrect.

sunup... Was supposed to by dyniphost.host.com
LajuanTaylorCommented:
@ccbbc_cs - Okay, I think the following should work for you. Please note, that I also added two entries to my Windows host file for the two domain names to simulate your DNS entries. This also allowed me to test if the URL rewrite rules would work.

This is one site with multiple host header bindings...

Please see the attached screen shots and updated web.config rules below. The web.config should be in the default site "wwwroot".

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>  				
			<rule name="app.mydomain.com" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^(.*)app.mydomain.com" />
                <add input="{PATH_INFO}" pattern="^/application/" negate="true" />
            </conditions>
            <action type="Rewrite" url="{R:0}/application" />
        </rule>
		<rule name="dyniphost.host.com" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^(.*)dyniphost.host.com" />
                <add input="{PATH_INFO}" pattern="^/application/" negate="true" />
            </conditions>
            <action type="Rewrite" url="{R:0}/application" />
        </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Open in new window

2015-12-30_2031_My_Site_Bindings.png
2015-12-30_2030_example_host_file_ed.png
2015-12-30_2020_URL_Rewrite1.png
2015-12-30_2028_Browse_Sites.png
2015-12-30_2029_Host_Header.png
Eric GreeneDirector of TechnologyAuthor Commented:
Sorry it took so long to come back to this.  Lot's of circumstances in the way.
LajuanTaylorCommented:
@ccbbc_cs - No problem. Glad to hear you got it resolved.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.