internal server error 500 with htaccess in custom directory - .htaccess

I use mysql dumper to work with my database. The program prompts me to create folder protection. After typing name and password, program created htaccess. and password files in dumper's directory. Unfortunately after I am not able to access the same url - internal server error. Permissions are - folders 755, files 644. Apache error log shows no record. Path in file is correct. Basicaly in any folder where I try to put this htaccess file becomes unavailable with internal server error. What can be the problem? Thank you.
This is content of newly created htaccess file
<IfModule mod_rewrite.c>
RewriteEngine off
</IfModule>
AuthName "MySQLDumper"
AuthType Basic
AuthUserFile "/data/web/xxx/web/dump/msd1.24.4/.htpasswd"
require valid-user

The problem was, I had to enable authn_file and auth_basic modules in apache for this to work.

Related

Showing Internal Server Error if i use .htaccess to enable the password procted folder [duplicate]

I tried to implement this code into my .htaccess on wordpress.
Everything works fine but when you get access, it throws an 500 Error and redirects me to my hosting park website. It seems that it doesn't load the content. Not sure if the problem is that the path I'm providing doesn't contain the actual content.
SetEnvIf Request_URI ^/quetecalles require_auth=true
AuthUserFile /kaycho.com/wp-admin/.htpasswrd
AuthName "Password Protected"
AuthType Basic
Order Deny,Allow
Deny from all
Satisfy any
Require valid-user
Allow from env=!require_auth
The snippet is based on this article
Error 500 protecting a single url with .htpasswd
AuthUserFile /kaycho.com/wp-admin/.htpasswrd
The file-path to your password file looks incorrect. This needs to be an absolute filesystem-path, not a root relative URL-path (which is what this looks like). If the path is incorrect and the password file cannot be found then you'll get a 500 Internal Server Error response when submitting the user/password.
Ideally, this should be a file-path outside of your document root directory - that is naturally inaccessible to user requests. It should not be in the same location as the .htaccess file implementing the protection.
Reference:
https://httpd.apache.org/docs/2.4/mod/mod_authn_file.html#authuserfile

Should I use the same folder for .htaccess and .htpasswd?

When I choose the same directory for .htaccess and .htpasswd, everything working fine.
But the situation below makes me sad.
I have one .htacces file in the root folder (johan) containing the code below.
AuthName "johan User"
AuthType Basic
AuthUserFile C:/wamp/www/johan/protectthisdir/.htpasswd
Require valid-user
.htpasswd is located at protectthisdir.
When I try to access the johan suddenly getting authentication required message box. But I need it only at protectthisdir. How to do this? Please help.
You should put the .htaccess file in the folder you want to protect, and not the root folder in your case.
The .htpasswd file should not be accessible from a browser so putting it above the DocumentRoot folder is a good idea. So in C:\wamp in your case.
PS:
It would be better to create a Virtual Host for your site to run in, in a completely different folder structure from the default wamp folders See this post for help on that

Password protection via .htaccess working in subdirectory but not in subdomain

I have a main site and a subdomain test site.
On the main site I have a folder previously used for testing...
/httpdocs/test/
Within that I have a htaccess file
AuthUserFile /var/www/vhosts/myurl.com/private/.htpasswd
AuthType Basic
AuthName "Login"
Require valid-user
And an associated .htpasswd in the location specified. This works perfectly.
However, using exactly the same .htaccess for my new subdomain does not work
i.e. putting the .htaccess file at
/subdomains/tests/httpdocs/
or any subdirectory.
Any suggestions why this might be? I get the login screen but it won't accept any correct username/password.
Thanks,
Nick

.htaccess & .htpasswd equals 500 error

I+m trying make a folder on my server protected by .htaccess & .htpasswd. When I try to enter the folder in question I'm asked for a password like I want. But then when the page is loaded I get a 500 error, which also happens on all pages on my site now. With ErrorDocument 500 it says:
This webpage has a redirect loop
The webpage at http://example.com/test/folder/ has resulted in too many redirects.
...
This is what my .htaccess file looks like:
ErrorDocument 500 http://81.18.24.170/test/appload/
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /test/folder/admin/.htpasswd
require valid-user
Can anyone see a problem or something that I've missed to make it work?
EDIT: I had the rewrite rule to prevent the 301 error I get for to many redirects. (Found in another solution but it didn't help.) So I just want to get rid of the 500 error.
When you are putting the file path for the AuthUserFile, make sure you use the FULL filepath from your root directory, for example:
AuthUserFile /var/www/html/test/folder/admin/.htpasswd
A similar issue was discussed in this thread:
htaccess / htpasswd in subdir

htaccess and htpasswd?

My first time using htaccess to ask for a user password.
on my server
.htpasswd file lies in my root directory of my server.
.htaccess file lies in folder folder "uploads" (which lies in the root dir)
i used …
<?php
echo dirname(__FILE__);
?>
to get the full server path to my root dir.
my .htaccess file in my "uploads" folder looks like this now:
AuthType Basic
AuthName "Uploads to my website"
AuthUserFile /home/.sites/74/site484/web .htpasswd
Require valid-user
and my .htpasswd file in the root looks like this:
admin:$apr4$CxS3O/..$vJcWNd6tlUwg6PAn.6cpA1
now when i browser to mydomain.com/uploads i get:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
what am i doing wrong here?
thank you for your help!!!
Looks like there's a space instead of a slash between the directory and file name in the AuthUserFile line.

Resources