Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite rule error: HTTP Error 500.50 - URL Rewrite Module Error. The expression "https://abc.com/{R:1}" cannot be expanded

Whenever someone makes request over HTTP protocol I rewrite the url to make it HTTPS. This is the code in web.config:

<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true">
    <match url="^(?!https://).*" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{SERVER_PORT}" pattern="80" ignoreCase="false" />
    </conditions>
    <action type="Rewrite" url="https://abc.com/{R:1}" />
</rule> 

However when I browse on http:// I get IIS error

HTTP Error 500.50 - URL Rewrite Module Error. The expression "https://abc.com/{R:1}" cannot be expanded.

How can I resolve this? I am utterly confused.

like image 316
TCM Avatar asked Aug 02 '11 17:08

TCM


1 Answers

The matches are zero based.

<action type="Rewrite" url="https://abc.com/{R:1}" />

Won't work because you only have one match. You need:

<action type="Rewrite" url="https://abc.com/{R:0}" />

Also, this won't work, because you can only match on the path below the site root.

<match url="^(?!https://).*" ignoreCase="false" />

It looks like you are checking for ssl. Try this instead:

      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
like image 146
SouthShoreAK Avatar answered Oct 10 '22 16:10

SouthShoreAK