Support

Admin Tools

#36425 htaccess restriction for subdirectory

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by on Sunday, 13 February 2022 20:17 CST

seagul30

Hi,

I use the htaccess maker in Admin Tools to create my .htaccess - which works fine for this website.

For specific reasions, now I have a subdirectory with a small upload script in two files:

/pdf-upload/index.php

/pdf-upload/upload.php

How can I protect this subdirectory with htaccess restriction.

I tried to copy a new .htaccess and .htpasswd file (that work on another server, with changed path) to the directory, but I get an error 500.

Is it possible to protect that subdirectory with .htaccess with Admin Tools?

Thanks

Sigrid

Β 

nicholas
Akeeba Staff
Manager

Can you please tell me exactly what you are trying to achieve? Do you want that folder password protected so even the upload scripts don't run? You want to prevent access to any file except the two .php file? Something else?

You can do all of that through the .htaccess Maker settings without copying any files. By their nature, .htaccess files cascade. In fact, they cascade through the filesystem. That's why the .htaccess file created by the .htaccess Maker in your site's root can protect all subdirectories under the site's root. I just need to know what you're trying to do so I can tell you how to do it :)

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

seagul30

I want to protect the folderΒ /pdf-upload/ so that only some people can upload files. I wanted to use the normal htaccess directory restriction with .htaccess and .htpasswd in that directory.

They should type username and password and be able to call the scripts and upload.

Right now it works but is accessible publicly - so anybody could upload a pdf.

But if I add a .htaccess and .htpasswd to the directory /pdf-upload/ I get an error 500.

nicholas
Akeeba Staff
Manager

I think that your main problem is that you have done something wrong with the .htaccess configuration in the subdirectory. But let's take this step by step.

First in the .htaccess Maker page find the Allow direct access to these files textarea and add the following lines

/pdf-upload/index.php
/pdf-upload/upload.php

This will allow users who have already gone through the password authentication to access these files.

From an SSH terminal go into your site's pdf-upload folder and type

htpasswd -c `pwd`/.htpasswd yourusername

Where yourusername is the username you want to use. You will be asked for a password, twice. This creates the initial .htpasswd file.

Now we need its absolute filename β€” because the .htaccess file requires the full filename, not just a relative one (yeah, I know, it's annoying!). In the SSH terminal type:

echo `pwd`/.htpasswd

This will reply with something like the following:

/home/myuser/public_html/pdf-upload/.htpasswd

Copy that. We'll need it in the next step.

Create a .htaccess file in the pdf-upload folder with the following content:

AuthName "Your dialog prompt"
AuthType Basic AuthUserFile /home/myuser/public_html/pdf-upload/.htpasswd Require valid-user

You need to change the things in bold type.

Your dialog prompt is what the browser authentication dialog title will be when someone tries to access the pdf-upload folder.

/home/myuser/public_html/pdf-upload/.htpasswd is what we copied from the echo command output earlier.

I have tested this with Apache 2.4. If you have a different web server your mileage may vary.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

seagul30

Thank you for your detailed description!

I could solve it now. I had not SSH access to this provider, so I generated the .htpasswd file otherwise.

Best regards

Sigrid

seagul30

just a side note
I wanted to close the ticket with the red button at the top.

rated with 5(very much), but then I get an error:

Error You are not allowed to create tickets in this category

nicholas
Akeeba Staff
Manager

Yeah, the rating feature has been on the chopping block for quite a while and hasn't been updated. The next version, Akeeba Ticket System 5, will not have it at all.

Star reviews had a place in time when the Internet was young and people were honest and responsible. I have reviewed several tickets with bad reviews and there was a disturbing pattern: if the issue requires the client to do something they rate the ticket bad even though they were told what is going on and how to fix it. If people downrate tickets because, for example, we have no control on the PHP configuration of their servers but tell them exactly what to ask their host (who are responsible for it!) to do, well, there's no point having ticket ratings. We already know which clients are problematic.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

System Task
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!