0

I have a SSL certificate for non www URL: https://domain.com

I know there are many similar question, but none of them seems to solve my problem. Here is what I am trying to do:

Problem:

1) http://www.domain.com -> https://domain.com **www to non www DONE**

2) http://domain.com -> https://domain.com **http to https DONE**

3) https://www.domain.com -> https://domain.com/ **NOT DONE**
      - Getting ERROR ON Above URL number (3): Your connection is not private

So far, my .htaccess file looks like so:

# www to non www
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule (.*) https://domain.com/$1 [R=301,L]

# http to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# https://www to htttps://

Please note that above code of .htaccess is working fine for my first and second problem, Now I want to solve my third problem

Here are the solutions that I already tried:

Community
  • 1
  • 1
Arun Pratap Singh
  • 395
  • 2
  • 4
  • 12

3 Answers3

0

Try this out. If this doesn't work then check in your site conf file you have AllowOverride All. If it is None make it All

Sample site.conf

<Directory /var/www/directory/>
    Options Indexes
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
Mike Rockétt
  • 8,947
  • 4
  • 45
  • 81
Haridarshan
  • 1,898
  • 1
  • 23
  • 38
0

Try this out:

To redirect www to non-www (while using SSL)

RewriteCond %{HTTP_HOST} ^www.your_domain.com$
RewriteCond %{SERVER_PORT} ^443
RewriteRule ^(.*)$ https://your_domain.com/$1 [R=301]

The last 2 are meant for online stores using SSL or to prevent any SSL errors while using SSL on some pages.

Update1:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{ENV:HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

Update 2

RewriteEngine On Make all http use https:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://xxx.yyy/$1 [L,R=301]

Make only www https use the non-www https:

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^www[.].+$
RewriteRule ^(.*)$ https://xxxx.yyy/$1 [L,R=301]

Update 3:

Check out this issue over here:

.htaccess redirect www to non-www with SSL/HTTPS

Community
  • 1
  • 1
Fakhruddin Ujjainwala
  • 2,493
  • 17
  • 26
0

Try :

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]

The rule above will redirect

to

And

to

Clear your browser's cache before testing this.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115