Link to home
Start Free TrialLog in
Avatar of janwestgard
janwestgard

asked on

IIS7 and redirection from root directory

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
Avatar of Bembi
Bembi
Flag of Germany image

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

Avatar of janwestgard
janwestgard

ASKER

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
<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.
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
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
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
ASKER CERTIFIED SOLUTION
Avatar of Bembi
Bembi
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
You are welcome... :-)
Please close the question if you are satified....