【问题标题】:PowerShell URL redirect from root to subdirectoryPowerShell URL 从根目录重定向到子目录
【发布时间】:2021-11-26 03:02:41
【问题描述】:

我正在尝试在 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"}

【问题讨论】:

    标签: powershell iis http-redirect


    【解决方案1】:

    尝试使用这个:

    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/httpRedirect" -name "enabled" -value "True"
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/httpRedirect" -name "destination" -value "websampletest"
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/httpRedirect" -name "httpResponseStatus" -value "Permanent"
    

    【讨论】:

    • Bruce Zhang,这有没有可能在 localhost:port 上不起作用?在运行 New-WebApplication 命令后,我正在运行 Set-WebConfigurationProperty 行。还是没有运气。
    • 运行set-webconfigurationProperty时,有没有报错信息?你运行了什么 new-webApplication 命令?
    • 看来我的 PowerShell 脚本中缺少以下内容:Add-WindowsFeature Web-Http-Redirect(请参阅下面的帖子)
    【解决方案2】:

    忘记在下面添加 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"
    

    【讨论】:

      猜你喜欢
      • 2011-10-24
      • 1970-01-01
      • 2019-07-20
      • 2015-04-23
      • 2012-06-03
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多