首页 > 解决方案 > PowerShell URL 从根目录重定向到子目录

问题描述

我正在尝试在 PowerShell 中构建一个部署脚本,以替换使用 IIS 用户界面的手动工作(这是用于 Docker 容器)。我找不到的一个步骤是如何将用户从根 url 导航到应用程序文件夹。因此,如果用户导航到www.site.com,他们会转到 www.site.com\WebSampleTest。

这是我到目前为止所拥有的:

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

标签: powershelliishttp-redirect

解决方案


忘记在下面添加 WindowsFeature:

Add-WindowsFeature Web-Http-Redirect

然后为实际重定向添加以下代码:

Set-WebConfigurationProperty -pspath 'IIS:\sites\Default Web Site'  -filter "system.webServer/httpRedirect" -name "enabled" -value "True"
Set-WebConfigurationProperty -pspath 'IIS:\sites\Default Web Site'  -filter "system.webServer/httpRedirect" -name "destination" -value "WebSampleTest"
Set-WebConfigurationProperty -pspath 'IIS:\sites\Default Web Site'  -filter "system.webServer/httpRedirect" -name "childOnly" -value "true"

推荐阅读