Home > other >  PowerShell URL redirect from root to subdirectory
PowerShell URL redirect from root to subdirectory

Time:10-08

I'm trying to build a deployment script in PowerShell to replace the manual work of using the IIS user interface (this is for a Docker container). The one step I cannot find is how to navigate users from the root url to the app folder. So if users navigate to www.site.com, they go to www.site.com\WebSampleTest.

This is what I have so far:

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

CodePudding user response:

Try to use this:

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"

CodePudding user response:

Forgot the add the WindowsFeature below:

Add-WindowsFeature Web-Http-Redirect

And then added the following code for the actual 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"
  • Related