Topic on Project:Support desk

Password protection in .htaccess asks for password in every directory accessed

1
Domenixq (talkcontribs)

I'm working on a private wiki instance on a shared host for a student organization. I'd like the wiki to be able to be read by anyone in the team who knows the password without the need to create a user just for that. Contribution is limited to registered users only.

I am using URL shortening and HTTPS redirection too, and currently it asks for password again not only when the main page is loaded but also when the logo is loaded and the first load.php command is ran, so three times usually. Sometimes it asks seemingly randomly also while browsing the wiki.

It is very annoying, and I contemplated on somehow extending MediaWiki to contain a landing page for password and then register the session and keep it until cookies are cleared. I couldn't find an Extension for what I am trying to do. I'd rather stick to .htaccess in case there is no such Extension available at all.


The content of the .htaccess file is the following:

RewriteEngine On

# Always redirect HTTP to HTTPS

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

<If "%{HTTPS} == 'on'">

    AuthType Basic

    AuthUserFile /var/www/exampleurl.com/wiki/.htpasswd

    AuthName "Username and password required"

    Require user exampleuser

</If>

RewriteRule ^/?wiki(/.*)?$ /index.php [L]

RewriteRule ^/*$ /index.php [L]


I am using MediaWiki 1.31.0.

Reply to "Password protection in .htaccess asks for password in every directory accessed"