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

一个人想着一个人 提交于 2019-12-12 08:20:02

问题


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.


回答1:


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>



回答2:


You can redirect through web config to Hope it will help full

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


来源:https://stackoverflow.com/questions/6916407/rewrite-rule-error-http-error-500-50-url-rewrite-module-error-the-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!