I have a website on shared host, the hosting default root directory is /public_html, but I place my website at /pulbic_html/web for file organizing purpose
I have registered for HTTPS from cloudflare
I wish for 2 results
- visitors can type https://example.com, https://www.example.com
- visitors can type http://example.com, http://www.example.com then redirect to either https://example.com or https://www.example.com
My current .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
Using the current .htaccess
- typing http://example.com -> working
- typing http://www.example.com -> working
- typing https://example.com -> working
- typing https://www.example.com -> working but redirect to http://example.com with connection not secure warning on the browser
I have googled and came up with
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]
with this .htaccess all testing result
please help to achieve these
- typing https://example.com, https://www.example.com -> working
- typing http://example.com, http://www.example.com -> redirect to either https://example.com or https://www.example.com
thanks all
