Getting a double slash when redirecting for a canonical hostname on Firefox only

Posted by Brian Neal on Pro Webmasters See other posts from Pro Webmasters or by Brian Neal
Published on 2011-11-27T20:29:25Z Indexed on 2011/11/28 2:04 UTC
Read the original article Hit count: 404

Filed under:
|
|
|

I have a Django powered website, and I'm trying to solve the "canonical hostname" problem. I want www.example.com to redirect to example.com. I have tried both techniques found in the Apache documentation here (scroll down to Canonical hostnames).

I'm currently trying the mod_rewrite method, and I have this in a virtual host container:

   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
   RewriteRule ^/?(.*)$ http://example.com/$1 [L,R=301,NE]

This works for me, except for one case. In Firefox only, if I type www.example.com in a browser, it redirects and I see this in the URL bar: example.com// (note the 2 trailing slashes).

However, something like this will work correctly: www.example.com/news/ gets redirected to example.com/news/.

I only see this on the root URL in Firefox. It seems to work fine on Windows under Chrome, IE9, and Opera (maybe those browsers eat the double slash?). My Mac using friend says it is fine in Safari, but he also sees the problem in Firefox.

As far as Django settings go, I am using the default value of APPEND_SLASH=True. I don't know if Django has anything to do with it, but I've tried mod_rewrite rules like the above on static HTML sites before and it always seems to work.

© Pro Webmasters or respective owner

Related posts about apache

Related posts about mod-rewrite