0

I'm going to start out with stating that I don't understand how to use regular expression, and I don't have the time to learn it in the near future. I've read an article that explains how to do exactly what I need, but when I try and do it, it simply isn't working and breaks the webpage completely (404 errors). Here's the article: IIS url rewrite role except some urls

My issue is, when I create the rewrite in the GUI, even if I type in the website and use 'exact match' instead of 'regular expression', it doesn't rewrite the URL the what it should (or the way I think it should, which I'm obviously wrong).

What I want to do:

  • If the client goes to myweb.site.com then redirect to myweb.site.com/login
  • Except when going directly to myweb.site.com/thispage.aspx

Here's the snip from the config file:

<rules>
            <rule name="Redirect to Client Login on root lookup" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="https://myweb.site.com" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{QUERY_STRING}" pattern="https://myweb.site.com/Default.aspx" negate="true" />
                </conditions>
                <action type="Rewrite" url="https://myweb.site.com/login" />
            </rule>

I'd prefer to do this in the GUI, but if I absolutely must manually edit the config then I'll do so.

Thanks in advance for any help! Sorry for not being more knowledgeable!

  • `` should only contain the resource-path and optionally the querystring, it should not contain the URI scheme (`http:` or `https`) or the host name and port number (`myweb.site.com`). – Dai Jul 10 '17 at 21:17
  • Also you have a full URL in the `{QUERY_STRING}` input condition. The querystring is the portion after the `?` character. – Dai Jul 10 '17 at 21:17
  • Please clarify if you want `/` to rewrite to `/login` or redirect to `/login`. I think a redirect makes more sense, otherwise you'll have two URLs with the same response content, which may confuse users. – Dai Jul 10 '17 at 21:20
  • I am looking to send clients from `/` to `/login`, so if a redirect is the proper way to do this, great! But for now, I'm not sure what to enter into the "Pattern" field in the GUI (the ` – Dr. Krieger Jul 10 '17 at 21:24

1 Answers1

0

In your case rule should be like that:

<rule name="root to login" stopProcessing="true">
    <match url="^$" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://myweb.site.com/login" appendQueryString="true" redirectType="Permanent" />
</rule>

This rule will redirect http://myweb.site.com to https://myweb.site.com/login only.

It will NOT redirect https://myweb.site.com to https://myweb.site.com/login. (If you want to allow that , just remove condiitons section)

In this line <match url="^$" /> url attribute should contains pattern for url path. In your case url path is empty(becasuse it is homepage), and regexp ^$ means empty string

Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36