I am attempting to write a .htaccess file to direct to and send index with an error code. Example index.php?error404 or index.php?error501.
I can direct an error within the root directory using the code below.
ErrorDocument 404 index.php?error=404
ErrorDocument 501 index.php?error=501
Example http://www.domain.com/file_does_not_exist.php and this works.
Result http://www.domain.com/index.php?error=404
The problem is catching and sending to index.php errors from sub directories.
Example http://www.domain.com/directory_does_not_exist Or
http://www.domain.com/directory_and/file_does_not_exist.php.
The result is http://www.domain.com/directory_does_not_exist/index.php?error=404 and therefore the CSS for the index.php in broken.
I have attempted the code below with no success. I am trying to redirect back to the index.php by rewriting the URL.
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^\/.\/\.php$ /index.php?s=$1 [R]
AND
RewriteCond $1 !^err[45][0-9][0-9]$
RewriteRule ^([/]?*)\.php$ /index.php?s=$1 [QSA,L]
Any help would be appreciated.
No need to use rewriting; just use absolute urls in your ErrorDocument directives (begin them with a
/):The docs show absolute urls in the examples: