How to install IIS URL Rewrite Module on Windows Server 2016 & IIS 10

When you start to play with Windows Server 2016 and IIS 10, you’ll receive an error when you try to install the IIS URL Rewrite Module in IIS. The error occurs because the URL Rewrite Module installer contains an invalid version check for the IIS being used. Here is how to install IIS URL Rewrite Module in IIS 10

IIS URL Rewrite Module installation error #

On Windows Server 2016 IIS 10, the IIS URL Rewrite module exits with the following error message:

IIS version 7.0 or greater is required to install IIS URL Rewrite Module 2.
IIS URL Rewrite Module installation error IIS 10
IIS URL Rewrite Module installation error IIS 10

The solution to successfully install URL Rewrite Module in IIS is quite easy: change IIS’ version number in the registry.

Change IIS’ version number in the registry and install URL Rewrite Module successfully #

You can use the following PowerShell snippet to change IIS’ version number in the Windows Server registry, allowing you to successfully install the IIS URL Rewrite Module:

# Install URL Rewrite module in Windows Server 2016 for IIS
if ( $osversion -ge "10.0" ) {
	Write-Host "[!] urlrewrite.msi checks the Windows Server IIS version `
		in the registry. This fails on Server 2016. `
		So temporarily change IIS version in the registry."

	$registryPath = "HKLM:\Software\Microsoft\InetStp"
	$Name = "MajorVersion"
	$currentValue = (Get-ItemProperty "hklm:Software\Microsoft\InetStp").MajorVersion
	$newvalue = "7"
	New-ItemProperty -Path $registryPath -Name $name -Value $newvalue -PropertyType DWORD -Force | Out-Null
}

Here you save the current IIS version in the variable $currentValue, so you can easily set the version number back to this original version.

I thought you might find this interesting:   WMI/netsh to add DNS servers on network adapters

Reset IIS’ version number:
After the URL Rewrite Module’s installation, you need to reset the IIS’ version number back to its original value:

if ( $osversion -ge "10.0" ) {
	Write-Host "[!] Reset IIS version in the registry"

	$registryPath = "HKLM:\Software\Microsoft\InetStp"
	$Name = "MajorVersion"
	New-ItemProperty -Path $registryPath -Name $name -Value $currentvalue -PropertyType DWORD -Force | Out-Null
}

Update: An updated version of IIS URL Rewrite is available for download: https://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads. Therefore, the above steps are no longer necessary in Windows Server 2016 RTM.

How to determine the Windows Server version using PowerShell? #

If you want to find out the version of Windows Server you’re running in PowerShell.
You can use this PowerShell snippet to easily and quickly look up the Windows Server version, and store it in variables:

$osversion = [System.Environment]::OSVersion.Version
$major = $osversion.Major
$minor = $osversion.Minor
Set-Variable -name windowsversion -value "$major.$minor" -scope script
# $windowsversion now contains: 10.0

A shorter variant is:

$osversion = [System.Environment]::OSVersion.Version
if ($osversion -ge (New-Object System.Version "10.0")) {
	Write-Host "Windows Server 2016"
}

Or use WMI’s Win32_OperatingSystem class, for example:

(Get-WmiObject -class Win32_OperatingSystem).Caption

This’ll return something like Microsoft Windows Server 2016 Standard

Please share this post if you found it useful, thank you! If you have a valuable tip, please let me know and drop me a comment.


Please Support Saotn.org

Each post on Sysadmins of the North takes a significant amount of time to research, write, and edit. Therefore, your donation helps a lot! For example, a donation of $3 U.S. buys me a cup of coffee, and as you know: things jsut work better with coffee. A $10 U.S. donation buys me one month of web hosting (yes, hosting costs money). But seriously, thank you for any amount. Much appreciated!

I thought you might find this interesting:   How to use .htaccess files on Windows Server IIS

Please donate to support this site if you found a post interesting or if it helped you solve a problem. Thanks! (Tip: no Paypal account required)

If you appreciated this post, then please donate using this Paypal button


Jan Reilink

My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.

Leave a Reply

2 Comments on "How to install IIS URL Rewrite Module on Windows Server 2016 & IIS 10"

Hi! Join the discussion, leave a reply!

Sort by:   newest | oldest | most voted
Anonymous
Guest

FYI – Microsoft has released URL Rewrite 2.1 which now includes support for Windows 2016 without need of registry tweak.