.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.
If you cannot see the .htaccess file in the root folder (//public_html) of your website, you may have to enable "Show Hidden Files" in your cP File Manager, or FTP client:
Examples:
The following lines, force all web traffic to use HTTPS when added in the .htaccess file in your website’s root folder.
If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
If your .htaccess file is empty add the following code:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder. Replace www.example.com with your own domain:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} folder RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
Additional information
Was this article helpful? If not please submit a request here
How helpful was this article?
Thanks for your feedback!