We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

condition only one host [Answered]RSS

1 reply

Last post Mar 25, 2020 02:55 AM by Jalpa Panchal

  • condition only one host

    Mar 24, 2020 12:35 PM|scascalesage|LINK

    Hello

    I only want to execute the rule if url contains .istinfor.com

    I have this rule but it doesn't work:

    <rewrite>
    			<outboundRules>
    				<!-- Add "SameSite=None" to any cookie which does NOT have it yet-->
    				<rule name="Add SameSite" preCondition="No SameSite">
    					<!--<match serverVariable="HTTP_HOST" pattern="^.istinfor.com$"  negate="true" />-->
    					<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
    					<action type="Rewrite" value="{R:0}; SameSite=None" /> 
    				</rule>
    
    				<!-- Add "Secure" to any cookie which does NOT have it yet, as long as it's HTTPS request or else a secure cookie would just be ignored -->
    				<rule name="Add Secure" preCondition="No Secure">
    					<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
    					<action type="Rewrite" value="{R:0}; Secure" />
    				</rule>
    
    				<preConditions>
    					<preCondition name="No SameSite">
    						<add input="{HTTP_HOST}" pattern=".istinfor.com" negate="true" /> 
    						<add input="{RESPONSE_Set_Cookie}" pattern="." />
    						<add input="{RESPONSE_Set_Cookie}" pattern="; SameSite=" negate="true"   />
    					</preCondition>
    					<preCondition name="No Secure">
    						<add input="{HTTP_HOST}" pattern=".istinfor.com" negate="true" /> 
    						<add input="{RESPONSE_Set_Cookie}" pattern="." />
    						<add input="{RESPONSE_Set_Cookie}" pattern="; Secure" negate="true" />
    						<add input="{HTTPS}" pattern="on" ignoreCase="true" />
    					</preCondition>
    				</preConditions>
    			</outboundRules>
    		</rewrite>

    Any suggestions? Thanks!

  • Re: condition only one host

    Mar 25, 2020 02:55 AM|Jalpa Panchal|LINK

    Hi,

    what is your actual requirement and what is the URL or hostname of your site? 

    You set the precondition that <add input="{HTTP_HOST}" pattern=".istinfor.com" negate="true" /> which means it does not match the hostname if you want to set only for the host .istinfor.com then you need to set the match URL means negate="false".

    also, try to run the failed request tracing and provide the tracing log it will help you to troubleshoot the issue.

    https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.