Hosting Discussion

Hosting Discussion (http://www.hostingdiscussion.com/)
-   Website Development & Design (http://www.hostingdiscussion.com/website-development-design/)
-   -   Force http to https with cPanel (http://www.hostingdiscussion.com/website-development-design/43957-force-http-https-cpanel.html)


danielpmc 02-12-2017 10:25 AM

Force http to https with cPanel
 
You need to have a SSL certificate in place before using the shown codes. Place one or the other in your cPanel public_html/.htacces file. Important: any .htaccess file must start with a dot and the chmod (pernmissions) are ALWAYS set at 644

If the .htaccess file does not have the "RewriteEngine on" in the file, uncomment by removing the hashtag. This only needs to appear once in the .htaccess file as it will cover all other Rewrites present and future.
Replace example dot com with your domain name

This forces all http pages to No WWW https
Code:

#RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

This forces all http pages to WWW https
Code:

#RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


LGvps 02-16-2017 02:52 PM

hello

about your post you can use :

Code:

  RewriteCond %{SERVER_PORT} 80
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Regards

bigredseo 02-17-2017 10:08 AM

If the server doesn't have "Rewrites" enabled by default, then your code will no work. You have commented out the first line (using the #).

It's always best to enable that, forcing the rewrites ON and then continuing with your rewrite statements.

You could also wrap the whole things in an IF MODULE statement for even better verification that the module is enabled.

danielpmc 02-17-2017 10:18 AM

Quote:

Originally Posted by danielpmc (Post 197453)
If the .htaccess file does not have the "RewriteEngine on" in the file, uncomment by removing the hashtag. This only needs to appear once in the .htaccess file as it will cover all other Rewrites present and future. Replace example dot com with your domain name

This is in my OP.

danielpmc 02-17-2017 11:33 AM

Quote:

Originally Posted by bigredseo (Post 197602)
You could also wrap the whole things in an IF MODULE statement for even better verification that the module is enabled.

Is this what you mean?

Code:

<IfModule mod_version.c>
<IfVersion >= 2.4>
SSL Code here
</IfVersion>
</IfModule>

<IfModule !mod_version.c>
<IfModule !mod_authz_core.c>
SSL Code here
</IfModule>

<IfModule mod_authz_core.c>
SSL Code here
</IfModule>


danielpmc 02-17-2017 12:01 PM

All examples shown above do not require any modules to be enabled beyond RewriteEngine on. They are forcing all traffic regardless if it is http/https coming through port 80 to force a redirection to its counterpart of https. These are not contingent on any SSL module to be enabled, as they are redirection codes to be used in a .htaccess file.

danielpmc 02-17-2017 02:17 PM

There is a potential, yet very slight, SEO redirect issue which is reported in Google Webmaster accounts for using this closing tag: [L,R=301]

Why: Because Google generally does not care for hard coded internal page redirects. Yes, some it accepts others it doesnt.

However, Google accepts this tag [R,L] as a soft coded redirect. I have not received a warning for using this tag.


All times are GMT -6. The time now is 05:29 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0