I was looking at two different variants of redirects:
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And noticed that in the first there is a slash between domain and URI, but in the second variant it's not explicitly inserted. So I tried looking for documentation, but couldn't find any on why/when/how they are automatically inserted.
I did some tests with a test tool and got the following results.
^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} -> https://sub.domain.com/test/folder/file.txt
^(.*)$ https://%{HTTP_HOST}/%{REQUEST_URI} -> https://sub.domain.com/test/folder/file.txt
^(.*)$ https://%{HTTP_HOST}/$1 -> https://sub.domain.com/test/folder/file.txt
^(.*)$ https://%{HTTP_HOST}/$1 -> https://sub.domain.comtest/folder/file.txt
Where the variants with variables seem to correct for missing/excess slashes, while the variants with regex don't.
But what's weird is that if I use only the domain, minus the URI,
^(.*)$ https://%{HTTP_HOST}/ -> https://sub.domain.com/
^(.*)$ https://%{HTTP_HOST} -> https://sub.domain.com/
The slash IS added, so it looks like the http_host variable includes a slash regardless of whether or not a URI is included. I.E. the slash is part of the domain name?
And potentially even weirder; that not including a domain at all and using only regex, DOES automatically add the slash and ends up with a workable URL.
^(.*)$ /$1 -> http://sub.domain.com/test/folder/file.txt
^(.*)$ $1 -> http://sub.domain.com/test/folder/file.txt
In short, using only variables automatically adds slashes, using only one variable adds slashes, using only regex adds slashes, but using regex after variables does not?
How exactly are these slashes added and what's the logic behind them?