Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Error 403 Page PHP

I created a .htaccess inside a directory in which I don't want the files to be directly accessed. It works and fires the default 403 page (Access forbidden!) of the Apache server. How can I create a custom 403 page? Thanks!

like image 246
fart-y-goer Avatar asked Jan 02 '12 17:01

fart-y-goer


People also ask

How do I fix PHP Error 403 Forbidden?

php. If there is no such page on your website, the visitors can encounter a 403 Error. Resolve this by uploading an index page to your httpdocs or public_html directory. If you already have a homepage named other than index, you can rename it or set up a redirect in your .

How do I trigger a 403 error?

The most common cause of a 403 Forbidden Error is simply inputting an incorrect URL. As discussed before, many tightly secured web servers disallow access to improper URLs. This could be anything from accessing a file directory to accessing a private page meant for other users.


2 Answers

In your .htaccess file you can specify what document you want as your default 403 error document.

ErrorDocument 403 /dir/file.html 

Here the directory is relative to the document root.

like image 162
JK. Avatar answered Sep 22 '22 12:09

JK.


You can do something like the following:


#Rewrite URL's
RewriteEngine On
RewriteRule ^404/?$ errors/404.html [NC]

# Enable Error Documents
# (404,File Not Found) | (403,Forbidden) | (500,Internal Server Error)
ErrorDocument 404 /404
ErrorDocument 403 /404

What this is doing is turning on the RewriteEngine so we can redirect url's nicely, then we are defining using the RewriteRule that /404/ or /404 should redirect to the custom 404 page. I then state that the ErrorDocument 404 and 403 should redirect to the 404 page. I do this for security so, a user does not know whether or not a file exists or if they just don't have access.

like image 24
Aramael Pena-Alcantara Avatar answered Sep 19 '22 12:09

Aramael Pena-Alcantara