0

I want to understand where is my mistake. I have an issue on my .htaccess, I want to redirect all the basics entries to https://www.example.com.

http://example.com to https://www.example.com
http://www.example.com to https://www.example.com
https://example.com to https://www.example.com
http://example.com/index.html to https://www.example.com
http://www.example.com/index.html to https://www.example.com
https://example.com/index.html to https://www.example.com

Everything has to be redirected to https://www.example.com but for the moment it doesn't work. Where is my error, and how can I improve the code?

My code:

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP:X-Forwarded-SSL} !on
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
    RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule . http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
    RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
    RewriteRule . %1 [R=301,NE,L]

Possible duplicate

Maybe I don't understand something but for me htaccess redirect to https://www doesn't answer my question, because it doesn't fix the /index.html part of my question.

halfer
  • 19,824
  • 17
  • 99
  • 186
user3659739
  • 434
  • 6
  • 19

1 Answers1

1

Change your rewrites in .htaccess file to this rules:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^\/index.(htm|html)$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ https://www.example.com/ [L,R=301]

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

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]
JarekBaran
  • 1,311
  • 2
  • 7
  • 12