Keep old url but redirect to new url - IIS - Asp.Net - .aspx

techthiru 40 Reputation points
2024-06-06T18:52:46.7233333+00:00

Running - IIS 10 - Asp. Net - Web Forms "Web Application" - .NET Framework 4.8

WebAppDemo is a web forms "application" under "Default Web Site"

Default Web Site
	WebAppDemo

Allows only a http:80 binding on default port 80.

Users use this URL to access this web application like so - http://webappdemo.domain.com/Default.aspx

Now, we want to create a "New Site" and only allow a https:9443 binding on a custom port :9443 (for example).

This "New Site" will contain the WebAppDemo as an application under it

New Site
	WebAppDemo

Now, I want the users to keep using the old URL which is http://webappdemo.domain.com/Default.aspx but be served/redirected to https://webappdemo.domain.com:9443/Default.aspx

Note the https: and the port # 9443 in the new URL.

How can I achieve this? Update: 06/08/24

I came up with this rule but the result is not working as expected.

When i browse this URL using a browser: http://dev-abc-iis.myorg.com/WebAppDemo

I am redirected to this URL : https://dev-abc-iis.myorg.com/WebAppDemo/

You can notice, in the redirected URL, the port number :9443 is missing and this result is not the expected result.

I am not sure if I got the rule correct or something wrong with it.

Any help to fix this is much appreciated.

My requirements for this rule:

http: requests made to only this application -> WebAppDemo running under "Default Web Site" should be redirected to the https: site which is bound to "WebAppDemo Site" -> WebAppDemo on the custom port :9443

Note:- There are other applications and i do not want to redirect their http urls to https: that is why i specified a URL match.

<rules>
	<rule name="WebAppDemo Https Redirect" stopProcessing="true">
		<match url="WebAppDemo(/.*)?$" />
		<conditions>
			<add input="{HTTPS}" pattern="^OFF$" />
			<add input="{HTTP_HOST}" pattern="([^/:]+)(:[^/]*)?" />
        </conditions>  			
		<action type="Redirect" url="https://{C:1}:9443/{R:0}" appendQueryString="false" />
	</rule>
</rules>
Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,362 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sam Wu-MSFT 7,131 Reputation points Microsoft Vendor
    2024-06-07T08:51:13.8866667+00:00

    @techthiru

    You can refer to this rule:

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

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.