Search code examples
iisweb-config

iis rewrite url for https://example.com/default.aspx/default.aspx to https://example.com


I have tried all kinds of rewrite URL's and can't get IIS to send the URL of https://example.com/default.aspx/default.aspx to https://example.com/default.aspx

Google has indexed the site with the wrong URL when Bing got it right (go figure). Any help would be much appreciated. All my traffic is going to the wrong url (https://example.com/default.aspx/default.aspx).

<rewrite>
  <rules>
    <rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^https://example.com/default.aspx/default.aspx" />
      </conditions>
      <action type="Redirect" url="default.aspx" />
    </rule>

    <rule name="redirect two character to default" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{URL}" pattern="^/[a-z]{2}(/)?$" />
      </conditions>
      <action type="Redirect" url="default.aspx" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

Solution

  • There is some issue in your rule. {HTTP_HOST} only matches the hostname which is www.example.com it will not match the whole URL.

    enter image description here

    You could try below rule:

    <rule name="Redirect www.xxx.com to xxx.com" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" />
      <conditions>
                        <add input="{HTTP_HOST}" pattern="www.example.com" />
                        <add input="{HTTPS}" pattern="on" />
                        <add input="{REQUEST_URI}" pattern="default/default|default.aspx/default.aspx" />
      </conditions>
      <action type="Redirect" url="default.aspx" />
    </rule>
    

    enter image description here