iis - web.config redirect non-www to www -
i need redirect non-www urls www url both http , https urls. tried following rules in web.config.
<rule name="redirect www" stopprocessing="true"> <match url=".*" /> <conditions> <add input="{http_host}" pattern="^domain.com$" /> </conditions> <action type="redirect" url="http://www.domain.com/{r:0}" redirecttype="permanent" />
<rule name="redirect www https" stopprocessing="true"> <match url=".*" /> <conditions> <add input="{https}" pattern="^domain.com$" /> </conditions> <action type="redirect" url="https://www.domain.com/{r:0}" redirecttype="permanent" />
it works non-ssl url in case of ssl redirect https://domain.com http://www.domain.com
please me correct rules.
for safer rule works both match any
, match all
situations, can use rewrite map solution. it’s solution drawback being ever slight effort set since need create rewrite map before create rule. in other words, if choose use sole method of handling protocol, you’ll safe.
you can create rewrite map called mapprotocol, can use {mapprotocol:{https}}
protocol within rule action.
<rewrite> <rules> <rule name="redirect www" stopprocessing="true"> <match url="(.*)" /> <conditions trackallcaptures="false"> <add input="{http_host}" pattern="^domain.com$" /> </conditions> <action type="redirect" url="{mapprotocol:{https}}://www.domain.com/{r:1}" /> </rule> </rules> <rewritemaps> <rewritemap name="mapprotocol"> <add key="on" value="https" /> <add key="off" value="http" /> </rewritemap> </rewritemaps> </rewrite>
Comments
Post a Comment