How to automate the setup/teardown of redirects in IIS?
For a while I have wanted to automate the setup of several redirects for an IIS-based web sites. W开发者_运维问答hat is the best way to achieve that?
Note: I am planning to answer my own question as soon as SO will let me do that. I just want to make sure I can find this solution later and help others.
You can use the ADSUTIL command to set the HttpRedirect property associated with a site, virtual directory or file.
For example to find out if a redirect is in place for the default.aspx of the web site with the id of 2:
cscript.exe adsutil.vbs get w3svc/2/Root/default.aspx/HttpRedirect
Now to set the redirect to "newlocation.aspx":
cscript.exe adsutil.vbs set w3svc/2/Root/default.aspx/HttpRedirect "http://mysite.com/newlocation.aspx, EXACT_DESTINATION"
And finally to remove the redirection you delete the property like so:
cscript.exe adsutil.vbs delete w3svc/2/Root/default.aspx/HttpRedirect
For more details on the HttpRedirect property, see MSDN
A word of caution: apparently the directory and file names are case-sensitive even though we're on a Windows OS. So make sure that you are using the right casing.
精彩评论