0

I have an apache2 webserver in AWS using bitnami. In my bitnami.conf file I need to rewrite all URLs to

https://www.example.com

I am able to redirect the following correctly

mydomain.com
http://example.com
www.example.com

But when the url is https://example.com it does not redirect to https://www.example.com.

my configuration is

<VirtualHost _default_:80>
      DocumentRoot "/opt/bitnami/apache2/htdocs"
      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteRule ^ - [E=protossl:s]
      RewriteCond %{HTTP_HOST} ^([a-z.]+)?example.com$ [NC]
      RewriteCond %{HTTP_HOST} !^www. [NC]
      RewriteRule .? http://www.%example.com%{REQUEST_URI} [R=301,L]
      RewriteRule /smecweb/(.*) /$1 [R=301]
      RewriteRule ^(/(.*))?$ https://www.%{SERVER_NAME}/$1 [R,L]

I tried to do something similar in <VirtualHost _default_:443>, but reverted it.

Can someone point out what am I doing wrong here?

MrWhite
  • 11,643
  • 4
  • 25
  • 40

1 Answers1

0

The RewriteCond and RewriteRule you are using doesn't sound right. What's the defined server name?

You can try this config:

Servername www.example.com
Serveralias  example.com
RewriteEngine on
RewriteRule (.*) https://%{HTTP_HOST}$1 [L,R=301,QSA,NE]
Mr Kashyap
  • 116
  • 4