custom error page for folder protected by htaccess - .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/

Related

401 error page not working with ht access auth

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

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

Set Status Code for Deny from

I want to block out user agents and tell them that the file doesn't even exist (Status Code: 404)
My current htaccess (Status Code: 403):
RewriteEngine on
SetEnvIfNoCase User-Agent UpdaterV* updater
Order Deny,Allow
Deny from All
Allow from env=updater
How can I fix this?
You can use mod-rewrite to get 404 status code :
RewriteEngine on
#--if user agent is not UpdaterV--#
RewriteCond %{HTTP_USER_AGENT} !UpdaterV [NC]
#--404 the request--#
RewriteRule ^ - [R=404,L]

.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).

.htaccess: RewriteCond works for xy.com/?id=12, but not for xy.com/index.php/?id=12

I am trying to password-protect a page with a given id somewhere in the query string. My .htaccess looks like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} id=12
RewriteRule (.*) $1 [E=protected_uri:1]
Order Deny,Allow
AuthName "Protected"
AuthType Basic
AuthUserFile /blabla/.htpasswd
AuthGroupFile /
Require valid-user
Order allow,deny
Allow from all
Deny from env=protected_uri
Satisfy any
This works fine for http://xy.com/?id=12, but it doesn't work for http://xy.com/index.php?id=12. For the second URL no password is needed.
I have no idea why this isn's working, because id=12 in the RewriteCond-Line should match all the URL's with id=12 in it?
Thanks for your help!
Ben

Resources