Search code examples
.htaccesserror-handlinghttp-status-code-403

How to handle 403 errors without redirecting to another page


My htaccess file currently handles 404 errors as following:

Options +MultiViews
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 404.html [L]

I did not use the ErrorDocument, because it redirects to an absolute error path.

I want to stay at the same url but show a custom template for a 403. Currently the 403 shows the default error page of apache... I would like to show a custom error document here too.

How would I do this?

Thanks for your help ;)


Solution

  • You can use ErrorDocument with a relative target path . With a relative path ErrorDocument directive won't redirect your request but instead show the error page without changing the url.

    ErrorDocument 403 /403.php