Problems can happen if users enter a Shortname for a site URL instead of the FQDN (Fully Qualified Domain Name). For example if a user types the URL as http://abc instead of http://abc.example.com, then the site certificate can come back as invalid, resulting as an error message or login prompt for the end user. Better to compensate for that by redirecting users to the FQDN if they enter the Shortname by accident.
Out of the box IIS has a feature included that is called URL Rewrite. This was not always the case, and in the past it was a separate download. In Windows 2012 and up URL Rewrite has been included with IIS as a key feature.
One of the key features of URL Rewrite is the ability to redirect a URL from Shortname to FQDN (Fully Qualified Domain Name). This is very useful to make sure that even if the user enters a Shortname instead of a FQDN URL, the user does not see an error message (or login prompt)
Here are the steps to use URL Rewrite. Note that you can set the same code settings at the IIS server level as well as at the individual site levels. In the case of the individual site levels, you will have to apply the code for each and any that you miss will not have the URL Rewrite logic applied, whereas if you apply the URL rewrite logic at the server level, it will apply to all sites by default. Tests using SharePoint sites in IIS are also good and this logic works quite well.
- To start, log into the server and open IIS
- Then choose either the Server Name to apply the URL Rewrite rule to all sites or click on an individual site to apply the URL Rewrite rule to just that site.
- Then once you have selected the server or the site, click the URL Rewrite tool under the main options:
- On the left hand Actions bar click the option to Add a Rule and then as an Inboud Rule type choose Blank Rule:
- Enter a unique name that you’d like to use to identify your new rule and then in the section called Match URL enter ^(.*)$ as the regular expression pattern. This basically says to match anything in the URL.
- Now here’s the important part where we are going to check if the user has entered the shortname instead of the FQDN. Expand the section called Conditions and click to Add a new condition with the following information:
- Set Condition Input to {HTTP_HOST}
- Set Dropdown Check if input string to: Does Not Match the Pattern
- Set the Pattern to: ^.*\.yoursite\.com
- Make sure the Ignore Case option is selected
- Finally in the section called Action:
- Change the Action Type dropdown to Redirect
- Enter the Redirect URL as: http://{HTTP_HOST}.yoursite.com/{R:1}
- Change the Redirect Type to Temporary (307).
NOTE: the Permanent (301) redirect type gets cached in user’s browsers so it can’t be changed without the users flushing their cache, so to be cautious it is best to set the redirect type to Temporary (307)
- Finally click the Apply button to add the changes. The URL Rewrite rule should now be in place and enforced by IIS.