Pts Admin

Pts Admin

  • NA
  • 12
  • 5.4k

How to rewrite rules for these two subdomains in web.config?

May 29 2018 12:46 AM
We have two public subdomains and one main domain in IIS/Windows server.
 
In the server we have main site hosted at: ../mysite.com/wwwroot/
 
subdomain 1 hosted at ../sub1.mysite.com/wwwroot
 
subdomain 2 hosted at ../sub2.mysite.com/wwwroot
 
we want to remove www and move to https permanently. We have implemented for main domain and is working fine. Now we want to implement the same for both the subdomains. We found some solution that is working fine for one subdomain when we placed the rewrite url in its web.config file. But when we placed the same rewrite rules for subdomain 2, then subdomain2 is not working.
 
Not sure what is the wrong.
 
Here is the code we placed for subdomain 1:
  1. <rule name="Remove www" stopProcessing="true">  
  2.         <match url="(.*)" ignoreCase="true" />  
  3.         <conditions logicalGrouping="MatchAll">  
  4.         <add input="{HTTP_HOST}" pattern="^www\.(.+)$" ignoreCase="true"/>  
  5.         </conditions>  
  6.         <action type="Redirect" url="https://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />  
  7.         </rule>  
  8.   
  9.         <rule name="http to https" stopProcessing="true">  
  10.                 <match url=".*" />  
  11.                 <conditions>  
  12.                     <add input="{HTTPS}" pattern="off" ignoreCase="true"/>  
  13.                 </conditions>  
  14.                 <action type="Redirect" url="https://sub1.mysite.com" redirectType="Permanent"/>  
  15.             </rule>  
Here is the code we placed for subdomain 2:
  1. <rule name="Remove www" stopProcessing="true">  
  2.         <match url="(.*)" ignoreCase="true" />  
  3.         <conditions logicalGrouping="MatchAll">  
  4.         <add input="{HTTP_HOST}" pattern="^www\.(.+)$" ignoreCase="true"/>  
  5.         </conditions>  
  6.         <action type="Redirect" url="https://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" />  
  7.         </rule>  
  8.   
  9.         <rule name="http to https" stopProcessing="true">  
  10.                 <match url=".*" />  
  11.                 <conditions>  
  12.                     <add input="{HTTPS}" pattern="off" ignoreCase="true"/>  
  13.                 </conditions>  
  14.                 <action type="Redirect" url="https://sub2.mysite.com" redirectType="Permanent"/>  
  15.             </rule>  

Answers (4)