Search code examples
url-rewritingappcmd

UrlRewrite via appcmd


I want to create urlrewrite url using appcmd for redirecting all requests from

http://

to

https://

I tried to google but nothing found. Could you provide me some basic example?


Solution

  • Got it working with this:

    appcmd.exe set config -section:system.webServer/rewrite/rules /+"[name='http_redirect',enabled='True']" /commit:apphost
    
    appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'] /match.url:"(.*)" /match.ignoreCase:true /commit:apphost
    
    appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'].conditions/add /+"[input='{HTTPS}',pattern='off']" /commit:apphost
    
    appcmd.exe set config -section:system.webServer/rewrite/rules.[name='http_redirect'].action /+"[type='Redirect',url='https://{HOST_NAME}/{R:1}',redirectType='Found']" /commit:apphost
    

    This link can help on building appcmd scripts.