.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

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>

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct