Monday, 2 May 2016

Annoying trailing double slash (at end of URL)

So sometimes, when people visit my web site, they seem to get (note the double slash) and which returns a 404. Annoying.

Why? The rewrite rule for Yii in .htaccess looked good and even though I have seen it myself, I cannot seem to recreate the bug.

Another example of the browser being really helpful and hiding what is really happening. Nice for the user (usually) but not for the developer.

The issue? I had a redirect all http to https in my Apache config. This was the problem. I had the line

RewriteRule .+$0 [R=301,QSA,L]

But note that it appends the request to the end of the domain that already has a trailing slash - silly boy. The browser remembers the 301 and so you never see the problem again.

The problem is that there are soooo many examples of how to do everything in rewrite/htaccess and some examples are even 20 lines long and people like me who are not very expert on the matter don't know which example to copy in our own sites.

Post a Comment