For the unsuspecting (like me): make sure your .htaccess
is being interpreted.
- Try placing an invalid line anywhere in
.htaccess
and see if you get an Internal Server Error in the browser. Otherwise, your file is being ignored.
- In the
VirtualHost
setting, note that the AllowOverride None
option causes .htaccess
to be ignored by Apache. Then review the VirtualHost
setting and set AllowOverride All
. For example, in /etc/apache2/sites-available/default
:
<VirtualHost *:80>
# ...
<Directory /var/www/pasta-do-meu-projeto/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
# AllowOverride None
Order allow,deny
allow from all
</Directory>
# ...
</VirtualHost>
-
Remember to restart Apache after modifying this:)
$ sudo service apache2 restart
-
Check the file's permission. I've seen lots of people indicating 644
;
$ chmod 644 /var/www/pasta-do-meu-projeto/.htaccess
-
Just to note, it is not necessary to restart Apache to see changes to .htaccess
(this is the idea of .htaccess
hehe)
Answering your question
Simple error message. I inserted the following line in my .htaccess
:
ErrorDocument 403 "Acesso negado!"
I created an empty folder, tried to access it, and received the expected error message.
Page with error message. I inserted the following line in my .htaccess
.
ErrorDocument 403 http://localhost/pasta-do-meu-projeto/403.html
I created an empty folder, tried to access it and saw the page with an error expected.
Not yet solved
For some reason, for error 403
, the local file does not work.
ErrorDocument 403 /403.html
I created an empty folder, tried to access it and received the following apache message:
Additionally, a 404 Error was encountered while trying to use an ErrorDocument to handle the request.
Some references (all in English):
UPDATE ON 01/17/2014, 13:53
I re-tested the configuration below and it worked without problems:
ErrorDocument 403 /403.html
NOTE: As a basis, I've used exactly the same% w / w as you posted.