Skip to content

Instantly share code, notes, and snippets.

@motowilliams
Created March 12, 2017 22:55
Show Gist options
  • Save motowilliams/af7e46536c857cb30ccdc06016cc90d0 to your computer and use it in GitHub Desktop.
Save motowilliams/af7e46536c857cb30ccdc06016cc90d0 to your computer and use it in GitHub Desktop.
Adds a rule to proxy yourhost.example.com to localhost:yourportnumber with IIS Url Rewrite
param (
[string]$domain,
[string]$hostName,
[string]$port
)
$ruleName = "$hostName-inbound"
$publicHost = "$hostName.$domain"
$privateHost = "http://localhost:$port/{R:1}"
$path = "MACHINE/WEBROOT/APPHOST/Default Web Site"
Add-WebConfigurationProperty -pspath $path -filter "system.webServer/rewrite/rules" -name "." -value @{name=$ruleName;stopProcessing='True'}
Set-WebConfigurationProperty -pspath $path -filter "system.webServer/rewrite/rules/rule[@name='$hostName-inbound']/match" -name "url" -value "(.*)"
Add-WebConfigurationProperty -pspath $path -filter "system.webServer/rewrite/rules/rule[@name='$hostName-inbound']/conditions" -name "." -value @{input='{HTTP_POST}';pattern=$publicHost}
Set-WebConfigurationProperty -pspath $path -filter "system.webServer/rewrite/rules/rule[@name='$hostName-inbound']/action" -name "type" -value "Rewrite"
Set-WebConfigurationProperty -pspath $path -filter "system.webServer/rewrite/rules/rule[@name='$hostName-inbound']/action" -name "url" -value $privateHost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment