Pregunta

In my .htaccess I do the following

The then php script takes the user to the relevant page / displays the relevant text

ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500
ErrorDocument 503 /error.php?e=503

For some of the errors I am attempting to send an automatic email.

1)How can I prevent the page from being accessed directly if not from apache e.g just by someone typing error.php?e=503

2)How can I get the last url visited (the url that triggered the error?

Thanks

¿Fue útil?

Solución

(1) Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500
ErrorDocument 503 /error.php?e=503

# block direct access to /error.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+error\.php[\s?] [NC]
RewriteRule ^ - [F]

(2) Inside /error.php access original URI using:

$_SERVER["REQUEST_URI"];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top