Trailing Slashes, IIS and F5 / Big-IP

We’ve had a problem on our websites at work for the last couple years where if a user doesn’t use a trailing slash when visiting a directory, ie:

http://www.hostname.com/mydirectory


the user gets a “The page cannot be displayed” error. The problem is that if you don’t use a trailing slash IIS sends a redirection to use the trailing slash:

REQUEST
---------------------
GET /mydirectory HTTP/1.1
Host: hostname.com


RESPONSE
---------------------
HTTP/1.x 302 Object Moved
Location: http://hostname.com:xxx/mydirectory/

Notice that the redirect includes the port designation? We run multiple websites on a single box and (for reasons beyond me) we don't use host headers so we have to use non standard ports in IIS. In the case above the web server thinks it's running the site on port xxx, which it technically is, but the world doesn't see that, nor can it use that port to access the site. At the time I thought it was the F5 that was redirecting users inappropriately, but there was nothing on the F5 website to back that up. There is now: How do I stop redirects from the web server behind BIG-IP?

In short, any website (IIS or Apache) running behind the F5 / Big-IP that is not using port 80 will show this behavior, there are a couple fixes:

a) use an IIS ISAPI filter (or mod_rewrite on Apache) to rewrite the redirects

b) use an F5 / Big-IP port redirect rule

c) use an F5 / Big-IP trailing slash redirect rule

If you read the tech note you'll see that Option 'b' will result in 2 redirects (client requests hostname.com/mydirectory --> IIS redirects to hostname.com:xxx/mydirectory/ --> Big-IP redirects to hostname.com/mydirectory/) and also lets any technical users know which port we're running on websites. Option 'c' is mentioned in the tech note as being the last gasp: "F5 Networks recommends using this rule only if there is no other alternative" so I chose option 'a'. There is a free ISAPI rewrite engine called (conveniently) ISAPI_Rewrite from helicontech.com. I installed it and then added the appropriate rewrite rule:

RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R]

and everything works again. Balance has been restored to the world.

One thought on “Trailing Slashes, IIS and F5 / Big-IP”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>