It took a little while to figure out the syntax of the rewrites and how to deploy via PowerShell. Most of the examples I found only provided the XML definition of the rule. Here are those two rules, ready for deployment via PowerShell (using the IIS PowerShell Snap-In).
Example: Redirect to HTTPS
$SiteName = "FIMSite"
$RuleName = "HTTP to HTTPS"
$Rule = @{
Name = $RuleName
patternSyntax = 'ECMAScript'
stopProcessing = 'True'
match = @{
url = '(.*)'
ignoreCase = 'True'
negate = 'False'
}
conditions = @{
logicalGrouping = 'MatchAll'
trackAllCaptures = 'True'
}
action = @{
type = 'Redirect'
url = 'https://{HTTP_HOST}/{R:1}'
appendQueryString = 'False'
redirectType = 'Permanent'
}
}
Add-WebConfigurationProperty -PSPath "IIS:\Sites\$SiteName" -Filter "/system.webServer/rewrite/rules" -Name "." -Value $Rule
$match = @{
input = '{HTTPS}'
matchType = 'Pattern'
pattern = 'off'
ignoreCase = 'True'
negate = 'False'
}
Add-WebConfigurationProperty -PSPath "IIS:\Sites\$SiteName" -Filter "/system.webServer/rewrite/rules/rule[@Name='$RuleName']/conditions" -Name "." -Value $match
Example: Redirect to Application
$SiteName = "FIMSite"
$RuleName = "Redirect to FIM Application"
$Rule = @{
Name = $RuleName
patternSyntax = 'ECMAScript'
stopProcessing = 'True'
match = @{
url = '^$'
ignoreCase = 'True'
negate = 'False'
}
action = @{
type = 'Redirect'
url = '/IdentityManagement/default.aspx'
appendQueryString = 'False'
redirectType = 'Permanent'
}
}
Add-WebConfigurationProperty -PSPath "IIS:\Sites\$SiteName" -Filter "/system.webServer/rewrite/rules" -Name "." -Value $Rule
No comments:
Post a Comment