Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Add a URL rewrite condition on IIS using Powershell

$
0
0

Hello, after searching the net and my powershell help command, i cannot find a solution to my problem.

So, i'm adding a rewrite rule to my website which works fine using following commands (the $_ is the variable  that contains my domainname coming from a csv file): 

Add-WebConfigurationProperty -pspath 'iis:\sites\SITENAME' -filter "system.webServer/rewrite/rules" -name "." -value @{name='Redirect www.' + $_ ;patternSyntax='Wildcard';stopProcessing='True'} Set-WebConfigurationProperty -pspath 'iis:\sites\SITENAME' -filter "system.webServer/rewrite/rules/rule[@name='Redirect www.$_']/match" -name "url" -value "*" Set-WebConfigurationProperty -pspath 'iis:\sites\SITENAME' -filter "system.webServer/rewrite/rules/rule[@name='Redirect www.$_']/conditions" -name "logicalGrouping" -value "MatchAny"

Set-WebConfigurationProperty -pspath 'iis:\sites\SITENAME'  -filter "system.webServer/rewrite/rules/rule[@name='Redirect www.$_']/action" -name "type" -value "Redirect"
Set-WebConfigurationProperty -pspath 'iis:\sites\SITENAME'  -filter "system.webServer/rewrite/rules/rule[@name='Redirect www.$_']/action" -name "url" -value "http://www.$_/{R:0}"

now i want to add a condition (redirect no www url to www), but i cannot find the way to address the collection which contains the conditions.

I want to add a condition with the following options

input= {HTTP_HOST}
matchtype = 0
pattern = domainname.com

Once i set these manually (using the GUI) i can query them using powershell 

Get-WebConfigurationProperty -PSPath 'IIS:\Sites\SITENAME' -Filter "system.webServer/rewrite/rules/rule[@name='Redirect www.domainname.com']/conditions" -name collection[0].pattern.value

but setting them seems impossible.

Can someone please point me in the right direction?

thanks a million!


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>