The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Trouble Rewriting From Sub-Domain

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #240444

    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 I would like it to be redirected to (HTTPS and no trailing slash), but it ends up being redirected to

    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.

Viewing 1 post (of 1 total)
  • The forum ‘Other’ is closed to new topics and replies.