如何通过命令行重定向iisstart.htm?

时间:2019-04-04 10:13:39

标签: windows powershell iis cmd url-redirection

我正在Windows Server 2016上运行iis10。 我需要将iisstart.htm(默认iis登陆页面)重定向到另一个URL。 有办法用命令行吗? 最好是powershell / appcmd。

我找到的最接近的东西是此命令,但这不是我所需要的,因为它会将任何请求重定向到此url,并且仅当该URL中未请求特定的Web应用程序时,才需要重定向。

Set-WebConfiguration system.webServer/httpRedirect "IIS:\sites\Default Web Site" -Value @{enabled="true";destination="domain.com";exactDestination="true";httpResponseStatus="Permanent"}

iisstart.htm redirect

1 个答案:

答案 0 :(得分:0)

IISStart.htm是默认登录页面的唯一原因是因为它已配置为默认文档。如果您只想重定向到其他文件,请使用“默认文档”。在这里(https://docs.microsoft.com/en-us/iis/configuration/system.webserver/defaultdocument/)上阅读它,但有一些脚本:

清除默认文档中的所有条目

POST

添加新的默认文档

Remove-WebConfigurationProperty  -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/defaultDocument/files" -name "."

从外观上看,您想重定向到OWA之类的文件夹。从技术上讲,使用HTTPRedirect(使用文件特定的配置)可能是可行的,但是即使可行,我也强烈建议您不要使用该功能。相反,我建议使用URL重写,不幸的是,可以在此处单独下载:https://www.iis.net/downloads/microsoft/url-rewrite我认为URL重写应该在所有IIS服务器上都可用。

可以在以下位置找到一些有关URL重写的良好示例:https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

否则,我希望您遵循的特定规则如下: 1)仅在未指定文件或文件夹(http://hostname/)的URL上匹配。 2)将这些请求重定向到http://hostname/owa/

示例URL重写脚本

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/defaultDocument/files" -name "." -value @{value='MySpecialLandingPage.html'}