when I visit the site:
https://example.com instead of
https://example.com/ in the browser address bar, I get
These two requests, with and without the trailing slash, are really the same thing. The browser will send the same request to your server in both cases. So, it's difficult to see why you would get a different response in these two cases, unless there was some local caching issue?
(See my answer to the following question on the Pro Webmasters stack for more information with regards to how the browser handles the trailing slash on the domain: https://webmasters.stackexchange.com/questions/35643/is-trailing-slash-automagically-added-on-click-of-home-page-url-in-browser)
RewriteRule directive in your
<VirtualHost *:80> container will always result in a double slash - so maybe you are seeing a cached response (or browser auto-completion) from this earlier (erroneous) redirect? Note that 301 redirects are cached hard by the browser.
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
In a virtualhost context, the
$1 backreference will capture the slash prefix on the URL-path (this differs from a directory or
You need to either remove the slash in the substitution, or take the first slash out of the captured pattern (or use the
REQUEST_URI server variable). For example:
RewriteRule ^/(.*) https://example.com/$1 [R=301,L]
(No need for the end-of-string anchor, since
* is greedy by default.)
And make sure your browser cache is cleared.