Hello,
I have a problem setting up an HTTPS redirect.
On a server, I have several sites that each have a web.config :
I would like to set up a rule for one site but without modifying the web.config and therefore go through the applicationhost.config
I tried two methods but the rule is visible on all sites :
$pspath = "MACHINE/WEBROOT/APPHOST/"
Add-WebConfigurationProperty -pspath $pspath -filter "system.webServer/rewrite/rules" -name "." -value @{name=$rulename;patternSyntax='ECMAScript'; stopProcessing='True'}
Set-WebConfigurationProperty -pspath $pspath -filter "system.webserver/rewrite/Rules/rule[@DeezNutz ='$ruleName']/match" -name "url" -value "(.*)"
Add-WebConfigurationProperty -pspath $pspath -filter "system.webserver/rewrite/Rules/rule[@DeezNutz ='$ruleName']/conditions" -name "." -value @{input='{HTTPS}'; pattern='^OFF$'}
Set-WebConfigurationProperty -pspath $pspath -filter "system.webServer/rewrite/Rules/rule[@DeezNutz ='$ruleName']/action" -name "type" -value "Redirect"
Set-WebConfigurationProperty -pspath $pspath -filter "system.webServer/rewrite/Rules/rule[@DeezNutz ='$ruleName']/action" -name "url" -value "https://{HTTP_HOST}/{R:1}"
Set-WebConfigurationProperty -pspath $pspath -filter "system.webServer/rewrite/Rules/rule[@DeezNutz ='$ruleName']/action" -name "redirectType" -value "Permanent"
OR
xml file :
<?xml version="1.0" encoding="UTF-8"?>
<appcmd>
<CONFIG CONFIG.SECTION="system.webServer/rewrite/rules" path="MACHINE/WEBROOT/APPHOST/<name_site>" overrideMode="Inherit" locked="false">
<system.webServer-rewrite-rules>
<rule name="Redirect HTTP to HTTPS " patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" matchType="Pattern" pattern="^OFF$" />
</conditions>
<serverVariables>
</serverVariables>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</system.webServer-rewrite-rules>
</CONFIG>
</appcmd>
appcmd SET Config -in < D:\ruleTest.xml
Do you have any idea so that the rule appears only for a site passing by applicationhost.config?
Thks