1

I tried to use .htaccess file to redirect http:// to https://
I also tried to append www. in front of domain-name, if it is not written.
I used this code in the .htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
Options -Indexes

# Force use https for secure connections
# (as it appears on your SSL certificate)
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# Force use www in front of domain-name
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

In Chrome and IE the site opens as expected
Jumps always to https://www.domain.com, no matter if the input address is "www.domain.com" or "domain.com" But in Firefox it works correctly only when the address is "domain.com"
When I place "www.domain.com", the Firefox browser turns it into
https://www.www.domain.com
I am sorry, but I simply cannot find the logic, why Chrome and IE interpret the .htaccess so well, and Firefox does it half way. Firefox is 41.0.2, the cache is empty, no change. I am out of guesses, could anyone suggest a solution?

1 Answers1

1

Thanks to Tyson now I have well working .htaccess file
Here is the code that worked. Change domain.com with your domain-name.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
Options -Indexes

# Always use www in the domain
RewriteCond %{HTTP_HOST} ^([a-z.]+)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1domain.com%{REQUEST_URI} [R=301,L]

# Check if HTTPS is not used, then jump to HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.domain.com/$1 [NC,R=301,L]

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]