Sunday 11 October 2020

htaccess redirect http to https not working 100% Solved

 If https not working in php website. Please change some changes in .htaccess file. 

<IfModule mod_rewrite.c>

     RewriteEngine On

     RewriteCond %{HTTPS} off

     RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTP_HOST} !^www\.

    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>


or

# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

OR

# Canonical HTTPS/non-WWW
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.rogws\.com [NC]
RewriteRule (.*) https://rogws.com/$1 [L,R=301]
</IfModule>

1 comment: