In IIS6 you can go into IIS Manager and set the properties of a file to be a permanent redirection, and there's also other tabs to set the security, headers, etc. See below for a screenshot.

IIS Manager File Properties

Is there a similar way to do this, but from the command line where I could do this for a thousand files at once?

For background: We are migrating content off this legacy system, but several external systems link directly to it. Those links will expire after a period of time, but updating those external systems will be a larger task than just setting redirects file by file to the new system (even by hand if needed).


Found an answer immediately after posting (which seems to happen all too often).

In IIS, you can configure redirects on file level. From within IIS Manager, this is done by right clicking the file, click Properties and then select "A redirection to a URL". This is however impractical if you need to do this on many files, so it can of course be done from a command line or by code. Using adsutil.vbs you can use the following command lines to set a redirection on an individual file:

CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs CREATE W3SVC/1/ROOT/vdir/oldFile.htm IIsWebFile 
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs SET W3SVC/1/ROOT/vdir/oldFile.htm/HttpRedirect "http://www.gafvert.info" 

In the example above, 1 is the website ID, vdir a virtual directory and oldFile.htm the file in the virtual directory.

Amending my answer now that I've tested it

On my Server 2003/IIS 6 box I could not use those exact commands, but instead had to execute like this to create the virtual file and then assign the KeyType/Properties.

SET FILE=/W3SVC/1/ROOT/test/redirection/File Path.pdf
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs CREATE "%FILE%"
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs SET "%FILE%/KeyType" "IIsWebFile"
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs SET "%FILE%/HttpRedirect" "http://www.google.com, EXACT_DESTINATION, PERMANENT"

You can also set content expiration, custom headers, etc. from this interface.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.