2

What I want is to redirect poo.example.com to poo.example.com/home.ashx but I am failing with the following code;

<rewrite>
  <rules>
    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
    </rule>
    <rule name="Redirect poo.example.com to poo.example.com/home.ashx" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="(./)" />
      <action type="Redirect" url="https://{HTTP_HOST}/home.ashx" />
    </rule>
  </rules>
</rewrite>

I am on IIS 7.5.

NOTE

I tired using default document but it didn't work. My app is an asp.net mvc app. It could be related to that but this is not an issue here. I need to implement that with IIS URL Rewrite feature.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
tugberk
  • 57,477
  • 67
  • 243
  • 335
  • perhaps [this](http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain) helps? – Precious Roy Jul 20 '11 at 13:48

2 Answers2

4

You could just add home.ashx as a default document in IIS (make sure it appears at the top of the list), then you wouldn't need do to any URL rewriting.

wsanville
  • 37,158
  • 8
  • 76
  • 101
  • tried that, didn't work. My app is an asp.net mvc app, I suppose default document didn't work because of that. – tugberk Jul 20 '11 at 13:42
  • Does it work if you request `/home.ashx` directly? Check to see if the request is being picked up by one of your routes, and if so, try ignoring requests to `.ashx` files before you map other routes: `IgnoreRoute("{handler}.ashx?{*path}");` – wsanville Jul 20 '11 at 13:49
  • yeah it works. You didn't get my question. I need a regex code to pick up the host url inside match node – tugberk Jul 20 '11 at 13:59
2

This will rewrite (internal redirect when URL will remain unchanged in browser):

<rule name="home.ashx" stopProcessing="true">
    <match url="^$" />
    <action type="Rewrite" url="/home.ashx" />
</rule>

This will redirect (301 Permanent Redirect):

<rule name="home.ashx" stopProcessing="true">
    <match url="^$" />
    <action type="Redirect" url="/home.ashx" />
</rule>

Because domain names are the same in source and target URLs (poo.example.com) there is no real need of specifying it in the rule -- IIS will put current domain automatically.

LazyOne
  • 158,824
  • 45
  • 388
  • 391