You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, we need to create the file with the user and passwords, and for that we
can use a free service like DynamicDrive
or use command below to generate the file in the server:
sudo htpasswd -c /var/www/.htpasswd myusername
Note that the file .htpasswd is genereated in the directory /var/www assuming
the website is located in /var/www/html, this file must never be publicly
accessible. For help with this command you can visit the documentation.
# This is required for the rules to work but if you already have it in your
# .htaccess, then there is no need to add this line.
RewriteEngine On
# Step 1 - Option A
#When the SSL certificate is not installed in the web server where the website is running.
# For example, when using Cloudflare's SSL or when the SSL certificate is installed in
# a load balancer but not in the web server.
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule .* - [E=protossl:1]
# Step 1 - Option B
# When the certificate is installed in the web server.
RewriteCond %{HTTPS} on
RewriteRule .* - [E=protossl:1]
# Step 2
RewriteCond "%{ENV:protossl}" !=1
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]