query string get appened more than once

2019-08-06 13:10发布

问题:

I am using url rewrite module (from here). I have following rule defined in my web.config to direct any http traffic to https.

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

I have one question. My url may also contains some encrypted and encoded data in query string. Seem like this rule is changing the parameters by appendding the query parameter more than once as shown below.

Actual url
http://www.MySite.com?Data=nBdHuQ6Jt2nHCnh5FG

After rule applied
https://www.MySite.com?Data=nBdHuQ6Jt2nHCnh5FG?Data=nBdHuQ6Jt2nHCnh5FG

Any ideas what I am doing wrong in this rule?

回答1:

You need to change {HTTP_HOST}{REQUEST_URI} for {HTTP_HOST}{URL}