Friday, June 24, 2011

want to quickly set custom errors in IIS 7 via command for several errors?

here is how:

for %%i in (401 403 404 405 406 412 500 501 502) do c:\Windows\System32\inetsrv\appcmd.exe set config /section:httpErrors /-[statusCode='%%i'].prefixLanguageFilePath /[statusCode='%%i'].path:"/vdir1/custom_error_file.htm" /[statusCode='%%i'].responseMode:Redirect /commit:apphost


this will set redirect for all the error codes listed in () above. If the path ever changes, run the same command , replace part in green with new URL to point to.

No comments: