IIS Rewrite Rule Translation

Dan 21 Reputation points
2022-11-17T16:45:22.127+00:00

Hi,

I have a couple of websites on my server, one for testing and one for a live environment, e.g:

https://preview.test.com (Test)
https://www.test.com (Live)

However when I enter https://preview.test.com I am directed to https://www.test.com (even when preview.test.com is stopped in IIS). I'm not sure what is causing the issue however suspect it may be something to do with URL rewrite. I have found the following code in the web.config but I'm unsure exactly what it does:

<rule name="Redirect rule1 for Redirects">  
	  <match url=".*" />  
	  <conditions>  
	     <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />  
	  </conditions>  
	  <action type="Redirect" redirectType="Found" url="{C:1}" appendQueryString="false" />  
</rule>  

If anyone could translate what it is doing into layman's terms and confirm if it could be affecting or not preview.test.com going to www.test.com I would be very grateful.

Many thanks,
Daniel

Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,416 questions
{count} votes

Accepted answer
  1. Michael Taylor 51,346 Reputation points
    2022-11-17T18:07:30.85+00:00

    It doesn't look like it is doing anything to me. I don't believe that is where your problem is.

    Are you hosting multiple sites on the same server or a single site with multiple child apps?
    In the bindings for the site(s) are you using host name bindings and are they correct for your site?
    If you disable the redirect rule does the problem go away?
    Bring up the browser tools (F12) and navigate to the preview site. Do you get a 301 back and the browser navigates or not?
    You posted the rules for one site but what about the other site?

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dan 21 Reputation points
    2022-11-18T10:23:47.463+00:00

    Thanks for your help!

    Multiple sites are being hosted on the same server. I've tried removing the redirect rule and the problem persists.

    The preview web.config rules are:

    <rewrite>  
          <rules>  
            <rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">  
              <match url="(.*)" />  
              <conditions logicalGrouping="MatchAny">  
                <add input="{HTTPS}" pattern="^OFF$" />  
              </conditions>  
              <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />  
            </rule>  
          </rules>  
    </rewrite>  
    

    The live web.config rules are:

    <rewrite>  
          <rewriteMaps configSource="config\IISRewriteMaps.config" />  
          <rules>  
            <rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">  
              <match url="(.*)" />  
              <conditions logicalGrouping="MatchAny">  
                <add input="{HTTPS}" pattern="^OFF$" />  
              </conditions>  
              <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />  
            </rule>  
            <rule name="Redirect rule1 for Redirects">  
       <match url=".*" />  
       <conditions>  
          <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />  
       </conditions>  
       <action type="Redirect" redirectType="Found" url="{C:1}" appendQueryString="false" />  
            </rule>  
          </rules>  
    </rewrite>  
    

    The IISRewriteMaps.config contains a couple of old URLs from an old website:

    <?xml version="1.0" encoding="utf-8" ?>  
    <rewriteMaps>  
     <rewriteMap name="Redirects">  
     <add key="/about-us/our-expertise/" value="https://www.test.com/about/" />  
     <add key="/contact-us/" value="https://www.test.com/contact" />  
     </rewriteMap>  
    </rewriteMaps>  
    

    No 301 redirect seems to occur, I've checked using browser tools (F12) and https://www.redirect-checker.org/.

    The bindings being used are:

    Live Website
    Type: http
    Host Name: www.test.com
    Port: 80
    IP Address: *

    Type: https
    Host Name: www.test.com
    Port: 443
    IP Address: *

    Test Website
    Type: http
    Host Name: preview.test.com
    Port: 80
    IP Address: *

    The issue only occurs for https://preview.test.com. http://preview.test.com goes to a page not found (HTTP error 404) which is expected as the site has been stopped in IIS.

    Could it be a DNS issue perhaps?