I am using a .htaccess file to pw protect a downloads folder. The website links to the files contained in the folder, and that works to some degree. When one clicks on a webpage link to the file in the folder, it pops up a login box, but goes to the file in the directory, rather than leaving them on the webpage from which they are accessing the file. This only occurs in the first instance of login, but after that, it works perfectly. To explain further, user goes to webpage, clicks link, .htaccess login pop-up displays, login occurs, but it displays only this file and path in the browser. I am an avid front end designer, but when it comes to the back end, please over explain.
I tried throwing in an html file with an auto refresh to the previous page, but it doesn't load that file.
AuthType Basic
AuthName "Access restricted"
AuthUserFile /home/dir/.members
AuthGroupFile /dev/null
AddType application/octet-stream .zip
AddType application/octet-stream .exe
require valid-user
Related
A friend wants me to implement basic file security on his site that he can look after himself.
I think the simplest option is to put a .htaccess file into the folder he wants to protect and that will redirect all requests to a php file in the root.
The php file will then check if the user is logged in and serve the file or request a fixed shared login password.
It's going ok so far except for two problems.
Firstly I can't get the htaccess file work based on the directory it is located in - I can only manage it by hard coding the directory into the htaccess file.
Secondly, I can get the php file to know the url of the file that was requested.
Any help and pointers would be great!
It sounds like what you are wanting to do can be done a little more easily with an .htpasswd setup.
You will just place this in an .htaccess of the directory you are trying to protect and all of the sub-directories will be protected as well.
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
And then create an .htpasswd file and use a tool like this to generate the credentials.
Alternatively, the way you are suggesting to do it will require the use of either cookies or sessions and here is another question that should help a bit more with setting that up.
Hi.I'm new at web, and I want to create a site. I've ordered a domain name and hosting, so now I have access to storage on hosting. What have I to do to protect any folder using htpasswd?
All that I have in http folder is index.html and folder examle, that contains .htaccess and .htpasswd and example2 folder, that should be protected.
When I try to access example2 folder from browser, I get popup window, that asking me for a login and password, and when I enter it I have a 500 internal sever error
Ok, so I have the answer. It's strange that the commentators didn't undertood the error, because as I understood the 500 error has only one meaning - server can't find a file. So, communyty members again talks about everytihng they can intstead that they was asked about-_-(yes, yes, there are a lot of grammar mistakes, but you understood(I hope)).
So here are a few steps for newers, like me, that can help to protect data of your site via `.htpasswd`
Getting the correct file path
Create file in folder you need to be protected, with .php extesion, and name it, how you like. Put this code there, and save it.
<?php
echo 'Полный путь к каталогу: ';
echo $_SERVER['DOCUMENT_ROOT'];
echo '/';
?>
Visit this page via browser, there will be wrote the full path to php document you've created.
Creating .htaccess and .htpasswd files
Go to folder you need to be protected by password and create two files - .htaccess and .htpasswd. You should notice, that these files shouldn't have any extensions, and they must be named exactly with . character in the begining.
Writing to .htaccess
Put there this one
AuthUserFile /path/to/.htpasswd
AuthType Basic
AuthName "My restricted Area"
Require valid-user
Instead of /path/to/ put the path you've got earlier. That's all
Writing to .htpasswd
Go to https://www.web2generators.com/apache-tools/htpasswd-generator and fill there login and password, and it will return you encrypted login:pass combination. Open .htpasswd file and just put it there.
That's all, it should work
A htaccess protected subdirectory of my website somehow has been indexed (months ago) by google. I had to add this directory to robots.txt but I don't want the protected url to be visible in robots.txt anymore.
I switched this directory to a new name and it won't probably be indexed again as it's not referenced anywhere but... just in case, I would like to add a noindex to it.
I added to my subdirectory .htaccess
Header set X-Robots-Tag "noindex"
It's working fine when I disable htaccess protection (I get the noindex header response). As soon as I add the protection
AuthType basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpassword
Require user admin
and simulate an error by hitting cancel on the authentication window, I get a 401 error and no "noindex" header.
Should I find a way to add a noindex on the 401 error page or is there an other way to manage that?
I'm trying to password protect a webpage, say index.html that's located at mysite.com/mysubfolder/index.html. How I've done this, is I've placed both a .htaccess and a .htpasswd file in the directory public_html/mysubfolder/, with .htacess containing the following:
AuthName "Secure Area"
AuthType Basic
AuthUserFile /public_html/mysubfolder/.htpasswd
Require valid-user
Now, when I type in www.mysite.com/mysubfolder into the address bar, I get the prompt to type in the user name and password, which I do, with the credentials that generated my .htpasswd file. But when I do, an empty page shows up - no error or warning, just a white page. I have other folders inside this directory, and for them too nothing shows up, when I try to access them directly through the address bar. When I click View Page Source, all I see is
<!-- SHTML Wrapper - 500 Server Error -->
I have no idea what to do now. I want everyone who types in that webpage or clicks through a link to it (mysite.com/mysubfolder/index.html or mysite.com/mysubfolder)to have to type in the specific credentials I have chosen. Am I doing something wrong? Maybe there is a better way? Thanks in advance.
I have password protected website with .htaccess. What I want to do now is to force users to login from the index.html page and not from any other which they can do now. ie. I have index.html (the main page) and I have two other pages 1.html and 2. html also protected with .htaccess password. Users can now type http://www.mypage.com/1.html and they will be asked for login data but I would like to force them (before they are asked for login details) to index.html to login. After they are loggedin they can use any link (ie.1.html or 2.html) as they want.
Can this be done by using .htaccess? I would need the whole code. Thank you!
With .htaccess you may protect the whole directory with password:
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /path/to/passwords/file/passwords
Require user myuser
you may create passwords file with the following command:
htpasswd -c /path/to/passwords/file/passwords myuser
You may complete description with good examples in Apache docs.
If you use apache to protect a directory you can't create a login form on your index.html for it. The login dialog is instead created by the browser.
You can however force people to first go to index.html, by checking the referrer header. If it exists and is different than domain.com/index.html you can redirect to index.html. You'll have to use mod_rewrite for this.