?
Solved

IIS7 and redirection from root directory

Posted on 2012-09-08
9
Medium Priority
?
661 Views
Last Modified: 2012-09-20
Hi,

I am trying to redirect users who come to my internal web site (on "server") by using DNS and "user friendly" names and. I am able to redirect all requests to "http://server/app1" by using the code:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Redirect" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="/app1" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

In this way I can access this server and application with "http://app1/". But if I have serveral "apps" on this server for example "app1", "app2" and "app3", is it possible to use a more advanced "rewrite" to match and redirect to more than one "url"?


/Jan
0
Comment
Question by:janwestgard
  • 5
  • 4
9 Comments
 
LVL 35

Expert Comment

by:Bembi
ID: 38383714
Something like this?

<rule name="Redirect Root Only" stopProcessing="true"> 
   <match url="\.com/$" /> 
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{HTTPS}" pattern="on" />
   </conditions>
   <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Found" />
</rule> 

Open in new window


or

<rule name="Redirect to WWW" stopProcessing="true"> 
          <match url=".*" /> 
          <conditions> 
            <add input="{HTTP_HOST}" pattern="^example.com$" /> 
          </conditions> 
          <action type="Redirect" url="http://www.example.com/{R:0}"   redirectType="Permanent" /> 
        </rule>

Open in new window


or

<rule name="Redirect to WWW" stopProcessing="true"> 
  <match url=".*" /> 
  <conditions logicalGrouping="MatchAny"> 
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" /> 
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" /> 
  </conditions> 
  <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" /> 
</rule> 

Open in new window

0
 

Author Comment

by:janwestgard
ID: 38387206
Hi,

And thanks a lot.

But I see now that I have not explained what I want to do good enough because the above examples will work if I can use parts of the application names in the "url". But in my case the Web apps. have names that I want to hide because they don't have nothing to do with the service behind the apps.

So one Web app. located under wwwroot and can be accessed with "http://server/difficult.application.name", another Web app. on the same server can be accessed with "http://server/even.more.difficult.application.name" and so on.

Instead of providing these names I would like to use something like "http://firstservice" and redirect that to "http://server/difficult.application.name" and "http://secondservice" and redirect that to "http://server/even.more.difficult.application.name".

I thougth I had to use something like:

<rules>
            <rule name="Redirect1" stopProcessing="true">
                <match url="firstservice" />
                <action type="Redirect" url="/difficult.application.name" />
            </rule>

and then another rule like:

           <rule name="Redirect2" stopProcessing="true">
              <match url="secondservice" />
              <action type="Redirect" url="/even.more.difficult.application.name" />
            </rule>
<rules>

But I am not able to figure this out so can you please help?

Thanks and kind regards,

/Jan
0
 
LVL 35

Expert Comment

by:Bembi
ID: 38388965
<match url="secondservice" /> should be either the full name...
or something like...
<match url="*secondservice*" />
You can use wildcards "*" and "?"

or the same in the conditions tag.

But following your description, it look more than hostheaders.
You can change the binding of your site in IIS...
If you enter a hostheader like "MySite" to a WebSite, you can call the site by
http://MySite

For hostheaders, you have additionally add a CNAME DNS entry, which points to the name of the WebServer. Otherwise the client does not find the Web-Server.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:janwestgard
ID: 38389852
Hi,

And thanks again. This is not my strong side so could you please give me an example of the syntax in "web.config" if I want  to redirect those two Web apps. I tried to explain above?

And for the hostheader, I will be using CNAME DNS entries.

Regards,

/Jan
0
 
LVL 35

Expert Comment

by:Bembi
ID: 38396191
OK, the complete steps...
First at all, you have to install URL Rewrite
You can install is from Microsoft Platform Installer:
http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2

IISRESET
This brings up a new "URL Rewrite" icon to create such rules.
You can then use this new icon, what results into:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
    <rewrite>
  <rules>
    <rule name="searchtext1" stopProcessing="true">
      <match url="ation1" />
      <action type="Redirect" url="http://target1" appendQueryString="false" />
    </rule>
    <rule name="Redirect2" stopProcessing="true">
      <match url="searchtext2" />
      <action type="Redirect" url="http://target2" appendQueryString="false" />
    </rule>
  </rules>
    </rewrite>
</system.webServer>
</configuration>

Open in new window


where searchtext1 is the first search expression and http://target1 the target.

Dependend from the position of the web.config (here assumed you use the default web site)
A request to http://myserver/anysearchtext1somewhere results in the site, which is hosted under http://app1

So vice versa, if you target website has the URL http://myserver/anycomplexwebtarget, and you want to reach this with http://myserver/app1, then
searchtext = app1
target =  http://myserver/anycomplexwebtarget

But in this case, also http://myserver/something-app1-something
results in the same target...

********

If you want to reach http://myserver/anycomplexname by typing  http://app1
(where "anycomplexname" is a seperate web application, not a folder under default web site).
then
a.) you set "app1" as host header for the anycomplexname web
b.) a DNS CName "anycomplexname" pointing to "myserver"
No rewrite is needed.
 
After all changes: IISRESET
0
 

Author Comment

by:janwestgard
ID: 38398563
Hi,

And thanks a lot for your help. First, I might have confused you when using the term “web app.” so just in case…

My Website structure is something like:

Sites
  - default web site
     - difficult.application.name
     - even.more.difficult.application.name
     - and so on…

So the Web applications I have been talking about are folders under the default web site. And after your last post I was able to access both “difficult.application.name” and “even.more.difficult.application.name” using “http://server/app1/” or “http://server/app2/” with your “rewrite” example.

But my goal was to use DNS CNAME and “http://app1/” and “http://app2/” to get to these applications. And still, despite your excellent help I have not been able to figure this out.

So instead, I have created to new sites on my web server:

Sites
  - default web site
     - difficult.application.name
     - even.more.difficult.application.name
     - and so on…
  - app1
  - app2

Where “app1” (DNS CNAME and host header = “app1”) is redirected to “difficult.application.name” and “app2” (DNS CNAME and host header = “app2”) is redirected to “even.more.difficult.application.name”.

This works so my problem is in a way solved. But it is possible to achieve the same result using “rewrite” isn’t it?

Regards,

/Jan
0
 
LVL 35

Accepted Solution

by:
Bembi earned 2000 total points
ID: 38398729
Assumed you have two CNAME records now for app1 and app2 pointing to your webserver.

Two possibilities:
CNAMES can only point to hostheaders....
... and hostheaders can only point to web sites...

Possibility1:
You move your web directories to a different location, ie from
C:\InetPub\wwroot...
- default website path
    - difficult.application.name
    - even.more.difficult.application.name

to
C:\InetPub\wwroot...
- default website path
- difficult.application.name
- even.more.difficult.application.name

Create two new Website in IIS and point the document root to the new file locations.
Add the associated host header to each new web site, so
app1 to the first one
app2 to the second one.

In this case, you don't need any rewrite..

Possibility2:
is your solution above

Possibility3:
The rewrite rule is located in the root of the default website and searches for app1 and app2 and redirects it to the subdirectories.
In the binding of the default web site, you have
* 80
you add one new binding for port 80 with hsotheader app1 and a second binding with app2 as hostheader.

But:
keep in mind with all redirection rules. As the rule uses app1 with wildcards (means includes app1), the redirection rule catches not only http://app1, but also subdirectories like http:\default web site\something different\somelikeapp1xxx

Nevertheless this is a complete different site, it is also redirected to app1. To avoid this, you have to define in the redirect rule only with exact match...
0
 

Author Comment

by:janwestgard
ID: 38405661
Hi,

Possibility 1 is not something I want to try because this is a supplier installed application that I don't want to make to much changes in.

I am not able to get possibility 3 to work so my syntax in web.config is probably not correct (I am not sure why...).

But I am using possibility 2 and it is working ok. So I probably have to settle for this solution even though I was hoping that a "rewrite" should do the trick.

Thanks a lot.

Regards,

/Jan
0
 
LVL 35

Expert Comment

by:Bembi
ID: 38415040
You are welcome... :-)
Please close the question if you are satified....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I came across an interesting issue that had me pulling my hair out.  I was troubleshooting a new internal web site which uses integrated security instead of anonymous.  When browsing the site from my laptop, I was able to access it with no iss…
Debug Tools to analyse IIS process: This article focus on taking memory dumps from IIS to determine which code is taking more time and to analyse which calls hangs/causes more CPU usage. To take dumps,download the following. Install1: To st…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question