Enable IIS Site Redirect With PowerShell

This post will show you how to use PowerShell on a Windows Server 2019 machine to enable IIS site redirect.

In our use case, we have a Windows Server 2019 web server running IIS 10, and we need to redirect one of the websites to another URL using PowerShell.

The code below has two variables currentsite, and redirecturl fill in the name of the current site (as shown in IIS) and the redirect URL. In our case, the URL is a top-level domain.

PowerShell Code

Copy the code below, change the name and URL and run.

import-module webAdministration
$currentsite = "website1"
$redirecturl = "https://www.ntweekly.com"
Set-WebConfiguration system.webServer/httpRedirect "IIS:\sites\$currentsite" -Value @{enabled="true";destination="$redirecturl";exactDestination="true";httpResponseStatus="Found"} -Verbose

Success! You're on the list.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.