Adding backslash ending to your URLs by UrlRewrite

It’s generally a best practice to add a backslash to your URLs, for performance reasons (let’s get back to that later in another post). There are several ways to do it, but the best/simplest way, IMO, is using UrlRewrite module. In most of the case, processing the Urls before it reaching the server code will be most effective, and here by using UrlRewrite we trust IIS to do the right thing. Our application does not even need to know about it. It’s also a matter of reusable. You can simply copy a working, well tested rule to another sites without having to worry much about compatibility.

Before getting started, it’s worth noting that UrlRewrite is an IIS module which is not installed by default, if you want to use it, then you would have to install it explicitly. Download and install it from https://www.iis.net/downloads/microsoft/url-rewrite .

And then we can simple add rules to <system.webServer><rewrite><rules> section in web.config. For the purpose of this post, this rule should be enough:

<rule name="Add trailing slash" stopProcessing="true">
  <match url="(.*[^/])$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>

If you are new to UrlRewrite, may be it’s useful to explain a bit on the rule. Here we want to add a rule which matches every url, except the urls which already end with backslash (/) already.

Continue reading “Adding backslash ending to your URLs by UrlRewrite”

Fixing HTTP Error 500.19 – Internal Server Error

When you are trying to setup an IIS website on your local machine/new server, it’s very likely that you are going to get this error

HTTP Error 500.19 – Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module   IIS Web Core
Notification   Unknown
Handler   Not yet determined
Error Code   0x8007000d
Config Error
Config File   \\?\C:\EL\EL\CMS\web.config
Requested URL   http://el:80/
Physical Path
Logon Method   Not yet determined
Logon User   Not yet determined

Config Source:

   -1: 
    0: 

More Information:

This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.View more information »

IIS could have had a better message of what is wrong, but we will have to live with this right now. Here’s the check lists you can go through:

Missing IIS features

Your IIS installation might be missing some critical features that are required to run the website (in this case, to parse the web.config). Make sure your IIS instance has all these features installed:

Missing IIS UrlRewrite module

The website might have URL Rewrite rules and your IIS does not have that installed. Simply go here https://www.iis.net/downloads/microsoft/url-rewrite, download and install it.