For the unsuspecting (like me): make sure that your .htaccess is being interpreted.
- Try placing an invalid line anywhere on
.htaccess and see if you get a Internal Server Error in the browser. Otherwise, your file is being ignored.
- In the configuration of
VirtualHost, note that the option AllowOverride None causes the .htaccess is ignored by Apache. Then review the configuration of VirtualHost and put 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 permission. I’ve seen a lot of people indicating 644;
$ chmod 644 /var/www/pasta-do-meu-projeto/.htaccess
Just for the record, you don’t need to restart Apache to see modifications to .htaccess (this is the idea of .htaccess hehe)
Answering your question
Simple error message. I inserted the next line into my .htaccess:
ErrorDocument 403 "Acesso negado!"
I created an empty folder, tried to access it and got the expected error message.
Page with error message. I inserted the next line into my .htaccess.
ErrorDocument 403 http://localhost/pasta-do-meu-projeto/403.html
I created an empty folder, tried to access it and saw the expected error page.
Unresolved
For some reason, for the mistake 403, local file does not work.
ErrorDocument 403 /403.html
I created an empty folder, tried to access it and received the following message from apache:
Additionally, a 404 Not Found error was encountered while trying to use an Errordocument to Handle the request.
Some references (all in English):
UPDATED 17/01/2014, 13:53
I tested again the configuration below and ran smoothly:
ErrorDocument 403 /403.html
NOTE: As a basis, I used exactly the same .htaccess that you published.
The problem is that the
index.phpwas not in theDocumentRoot. I added the right path, solved.– Calebe Oliveira