401 error page not working with ht access auth - .htaccess

Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.
I've been getting this error and the custom 401 page isn't getting triggered.
I've searched the whole of stackoverflow for answers and a few which I found didn't worked. Like allowing URL etc.
Can anyone tell where I am doing it wrong;.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
ErrorDocument 404 /404/
ErrorDocument 401 /var/www/www-root/data/www/jackjonanune.com/duck.html
AuthUserFile /var/www/www-root/data/www/jackjonanune.com/.htpasswd
AuthName "Must Log In"
AuthType Basic
require valid-user
Order allow,deny
Allow from 103.221.211.201
satisfy any
I also tried adding
<Location /var/www/www-root/data/www/jackjonanune.com>
Allow from all
Satisfy Any
</Location>
But it brings in 500 internal server error

Related

htaccess redirect empty uri instead of directory listing

If I just do Options -Indexes
localhost/subdir/ would give me 500 error.
But I want to redirect it to https://github.com/miranda-zhang/cloud-computing-schema
Something like
RewriteRule ^$ https://github.com/miranda-zhang/cloud-computing-schema [R=308,L]
Currently, this doesn't work on my local server.
I have to do
RewriteRule ^home$ https://github.com/miranda-zhang/cloud-computing-schema [R=308,L]
And use the url localhost/subdir/home
Also Options -Indexes seem to make the following stop working.
ErrorDocument 406 https://miranda-zhang.github.io/cloud-computing-schema/v1.0/406.html
RewriteRule ^.*$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/406.html [R=406,L]
Full original .htaccess file
I also tried some methods in Problem detecting empty REQUEST_URI with Apache mod_rewrite
The following doesn't seem to work, or maybe I'm missing some other config.
RewriteCond %{HTTP_HOST} ^localhost/coocon
Or
RewriteCond %{REQUEST_URI} "^/$"
Seems something else was wrong, it is a 403 error now.
Forbidden
You don't have permission to access /cocoon/ on this server.
Cannot serve directory /var/www/html/cocoon/: No matching
DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
This might work:
Options -Indexes
ErrorDocument 403 https://github.com/miranda-zhang/cloud-computing-schema

custom error page for folder protected by htaccess

I want to send the user to a custom error message when an incorrect username of password is used. I still get the default error message along with a message that ErrorDocument line is incorrect. I don't know what is wrong with the code Please help. This is my code
AuthType Basic
AuthUserFile /home/aoswald/njlti.aoswald/pubs/.htpasswd
AuthName "Publications Area"
require valid-user
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(?:www\.)?njlti\.aoswald\.com(?:$|/) [NC]
RewriteRule \.(gif)$ - [F,NC]
ErrorDocument 401 http://njlti.aoswald.com/401.html
It seems that you can not use full URL in ErrorDocument
but something like this:
ErrorDocument 401 /401.html
reference: http://tosbourn.com/notice-cannot-use-a-full-url-in-a-401-errordocument-directive-ignoring/

.htaccess auth with hiding target directory

I'm looking for a way I could hide directory (giving 404 instead of it) before user logging in.
For example, I have directory /admin and directory /login
And I want that the user which go on the first address - will see 404 page.
But, if he goes first at second page, he will see basic auth dialog and if he type correct login data - he will be redirected to first directory and see actually admin panel.
How to do this, could you tell me please? I've tried various combinations (including symlinks) but all I get - accessible /admin directory, if it was password protected (if not - it correctly redirects to 404, no matter with RewriteRule or RedirectMatch).
RedirectMatch 404 ^/admin(/?|/.*)$
RewriteRule .* - [E=AUTH:%{HTTP:Authorization}]
<Files login>
AuthUserFile /www/.passwd
AuthName PROXY
AuthType Basic
Require valid-user
</Files>
RewriteCond %{AUTH} !=""
RewriteRule .* login
Not working (getting 404 continuously).
RedirectMatch 404 ^/admin(/?|/.*)$
RewriteRule ^login/(.*) admin/$1
RewriteCond %{THE_REQUEST} ^GET\ /admin/
RewriteRule ^admin/(.*) /login/$1 [L]
Not working while .htaccess is present in admin directory (otherwise it became unprotected).

HTTP Digest authentication fails with Ajax requests

Apologies if this should be on ServerFault, please move/vote to move if necessary.
I have come across a problem with a .htpasswd file whereby
Accessing a page normally requests a username and password as expected
I can then browse the site as expected and navigate through pages without authentication being requested on each page load.
Accessing a page on the same server, same base URL, using the same protocol but using AJAX re-requests authentication.
If I then authenticate, the AJAX request is successful, but the authentication on the main browser window is no longer valid and therefore the next refresh requests authentication.
This only happens on one vhost of many on the server, all of which use the same .htpasswd file. The Request for authentication is in the global Apache config file, and not specific to a vhost.
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
AuthUserFile /var/www/private/.htpasswd
AuthGroupFile /dev/null
AuthName "My Private Directory"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
</Directory>
The .htaccess file in the only vhost in which it does not work is as follows. Nothing special which should affect it.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !.*\.(gif|png|jpe?g|ico|swf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/=$1 [L,QSA]
</IfModule>
My question therefore is why do AJAX requests require a user to authenticate again?

Htaccess redirect not working?

I am trying to use an htaccess redirect, and for some reason when I try to redirect the user, instead of going to page.html, it tries to go to page.htmlpage.htmlpage.htmlpage.html and it just keeps on repeating it. Anyone have any clue what I am going wrong?
Here is my htaccess file:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName 2enetwork.x10hosting.com
Options All -Indexes
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
Redirect / http://2enetwork.tk/under_construction.html
#RewriteEngine On
#RewriteRule ^(.*)$ ./under_construction.html [L]
Oh, and also, it will give me a 403 error and underneath that it says and addition 302 error was found. If I comment the Redirect / http://2enetwork.tk/under_construction.html, it works fine. There is nothing wrong with the site, and I can see the under construction page fine.
Ok, I figured out why. When I sat there and tried to rediret my site, I redirected the whole site to uc.html (under_construction.html), and uc.html is included in the rest of the site, so it would then try to redirect to uc.html again, and again, and again in a never ending loop. So, my new question is, How do I prevent this from happening? Is there a way I can redirect my whole site minus uc.html?
Anything more complex than a brute force "go there" needs mod_rewrite.
This hasn't been tested, but...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !under_construction\.html$
RewriteRule ^(.*)$ ./under_construction.html [L]
This RewriteCond line tells it to rewrite all requests except ones for files named under_construction.html*.
* Techinically, all files that end with the string "under_construction.html".

Resources