.htaccess does not work when using https
Hello, I want to protect one directory using user / password via .htaccess
.htaccess work fine when using http but never work when using https
Please see the two examples below:
https://dccoilfieldsupply.com/__s_ecret2/src/day_file_tr/205.pdf
http://dccoilfieldsupply.com/__s_ecret2/src/day_file_tr/205.pdf
Please help me with this problem
1 Reply
mjones
Linode Staff
There looks to be a few different ways to set this up. This Stack Overflow thread has some suggestions on how to configure your .htaccess file. For example, you can redirect any HTTP connections to HTTPS, then set up authentication for HTTPS connections:
# Redirect to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Authenticate users only when using HTTPS
<If "%{HTTPS} == 'on'">
AuthType Basic
AuthName "Example Text"
AuthUserFile /etc/example.htpasswd
# Prevent this 'Require' directive from overriding any merged previously
<IfVersion >= 2.4>
AuthMerging And
</IfVersion>
Require valid-user
</If>