Reputation: 4873
Trying to make a rewrite rule to force HTTPS without www
# strip WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have tried a million different variations.
I can strip HTTP request of the www, but it does not redirect to HTTPS
I can not strip HTTPS request of the www
What am I missing here?
Upvotes: 0
Views: 81
Reputation: 4714
Bitnami Engineer here,
If you always want to access your site using https://www., this configuration should be similar to the one you need to use
In your case, edit the apache2/conf/bitnami/bitnami.conf file and use the following configuration:
<VirtualHost _default_:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://www.example.com$1 [R=permanent,L]
...
<VirtualHost _default_:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://www.example.com$1 [R=permanent,L]
...
Upvotes: 1