- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I’m trying to create a portable rewrite (Apache) for any time a request is made to a sub-domain without HTTPS and/or without a trailing slash (to enforce no trailing slash for non-directories). I have the following rules in place:
# Redirect any non-directory subdomain req w/ trailing slash to HTTPS URL w/out trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.*)/$ [NC]
RewriteCond %{HTTP_HOST} ^(?!www\.)([a-z0-9]+\.[a-z0-9-.]{2,}\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)/$ https://%1/$1 [R=301,L]
# Redirect any non-directory and non-HTTPS req w/out trailing slash to HTTPS
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTPS} !On
RewriteCond %{HTTP_HOST} ^(?!www\.)([a-z0-9]+\.[a-z0-9-.]{2,}\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,L]
When there is a request to http://sub.example.com/aaa/ I would like it to be redirected to https://sub.example.com/aaa (HTTPS and no trailing slash), but it ends up being redirected to https://sub.example.com/sub/aaa.
Does anyone know how I could change the above rules to achieve what I’m looking for or possibly change some other Apache setting maybe? Having trouble understanding why ‘sub’ is being prepended to the REQUEST_URI. Any help would be greatly appreciated. Sorry if this is something that could be found with search. I’ve tried, I’m just not sure exactly what to search for I guess.