繁体   English   中英

IIS配置中的URL重写引发Http404错误

[英]IIS configuration for URL rewrite throwing Http404 error

我在一个网站上工作,我需要将URL从http重定向到https。 我的网址看起来像:(我每次都使用随机令牌ID生成此网址)

http://testsite.local/login.aspx/activate?token =(随机生成的令牌ID)

我想将此网址重定向到

https://testsite.local/login.aspx/activate?token =(随机生成的令牌ID)

以下是IIS中的URL重写设置:

在此处输入图片说明

Web.config文件:

 <rewrite>
            <rules>
                <rule name="http redirect">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Rewrite" url="https://{HTTP_HOST}{REQUEST_URI}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>

输入URL时,我看到Http404错误。 在这里提到-我在IIS中选中了“需要SSL”条件。 我知道匹配的模式看起来不对,但不确定解决方案。 有什么帮助吗?

尝试将{REQUEST_URI}更改为{R:1}可能会解决此问题。

  • {R:x}用作规则模式()的后向引用。

在我的机器上工作。

像这样:

<rule name="HTTPS rewrite" enabled="true" stopProcessing="true"> 
          <match url="(.*)"/>  
          <conditions> 
            <add input="{HTTPS}" pattern="^OFF$"/> 
          </conditions>  
          <action type="Rewrite" url="https://{HTTP_HOST}{R:1}" logRewrittenUrl="true" />
        </rule> 

顺便说一句,您提到需要Redirect HTTP通信Redirect到HTTPS。 但是,似乎您正在尝试将HTTP流量Rewrite为HTTPS,以作为反向代理。

如果您想配置正确的301 HTTP重定向,请使用Redirect而不是Rewrite

像这样:

        <rule name="HTTPS force" enabled="true" stopProcessing="true"> 
          <match url="(.*)"/>  
          <conditions> 
            <add input="{HTTPS}" pattern="^OFF$"/> 
          </conditions>  
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/> 
        </rule> 

我遵循了@Anduin提到的更改。 伴随这些更改,我为该站点创建了端口80绑定,该规则运行良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM