too long

I am having a bit of trouble with this one. I am looking to have any error code that a user gets (400,401,403,404,500) route to a page called error.php in the root directory.

I've researched what I could online about it, but to no avail have I found any luck. My problem is a bit more unique and my knowledge of an htaccess file is sadly basic.

Here is the code:

## Route error pages
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

Options +FollowSymlinks -Multiviews -Indexes
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ $1.php
RewriteRule ^item/(.*)$ ./itemlookup.php?search=$1
RewriteRule ^recipe/(.*)$ ./recipelookup.php?search=$1
RewriteRule ^secret/recipe/(.*)$ ./secret/recipelookup.php?search=$1
RewriteRule ^api/json/idbyname/(.*)$ ./api/json/getidbyname.php?id=$1 [QSA]
RewriteRule ^api/csv/idbyname/(.*)$ ./api/csv/getidbyname.php?id=$1 [QSA]
RewriteRule ^api/json/item/(.*)$ ./api/json/items.php?id=$1 [QSA]
RewriteRule ^api/csv/item/(.*)$ ./api/csv/items.php?id=$1 [QSA]
RewriteRule ^api/json/forge/(.*)$ ./api/json/mysticforge.php?id=$1 [QSA]
RewriteRule ^api/csv/forge/(.*)$ ./api/csv/mysticforge.php?id=$1 [QSA]
RewriteRule ^api/json/history/(.*)$ ./api/json/tradehistory.php?id=$1 [QSA]
RewriteRule ^api/csv/history/(.*)$ ./api/csv/tradehistory.php?id=$1 [QSA]
RewriteRule ^api/json/history-daily/(.*)$ ./api/json/tradehistorydaily.php?id=$1 [QSA]
RewriteRule ^api/csv/history-daily/(.*)$ ./api/csv/tradehistorydaily.php?id=$1 [QSA]
RewriteRule ^api/json/recipe/(.*)$ ./api/json/craftingrecipes.php?id=$1 [QSA]
RewriteRule ^api/csv/recipe/(.*)$ ./api/csv/craftingrecipes.php?id=$1 [QSA]
RewriteRule ^api/json/exchange/(.*)$ ./api/json/gemexchange.php [QSA]
RewriteRule ^api/csv/exchange/(.*)$ ./api/csv/gemexchange.php [QSA]

#Gzip Compression, Saves on bandwidth
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript application/vnd.ms-fontobject application/x-font-ttf image/svg+xml
</ifmodule>
#End Gzip

## EXPIRES CACHING - 1 Month ##
<FilesMatch "\.(gif|png|jpg|jpeg|woff|woff2|svg)$">
ExpiresActive on 
ExpiresDefault "access plus 1 month"
</FilesMatch>
<FilesMatch "^(jquery-1\.9\.1\.min\.js)$">
ExpiresActive on 
ExpiresDefault "access plus 1 year"
</FilesMatch>

My users will see existing pages correctly. But any what would be 404 page errors and it's likeness will reroute to a 500 internal server error (without error page routing).

So in a nutshell the ErrorDocument lines aren't working. All help is certainly appreciated!

Sincerely, RebornGeek

  1. Keep .php adding rule at last.
  2. Add .php only if matching file exists.

Replace your rules with this:

## Route error pages
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php

Options +FollowSymlinks -Multiviews -Indexes
RewriteEngine on

RewriteRule ^(index|error)\.php$ - [L,NC]

RewriteRule ^item/(.*)$ itemlookup.php?search=$1 [L,QSA]
RewriteRule ^recipe/(.*)$ recipelookup.php?search=$1 [L,QSA]
RewriteRule ^secret/recipe/(.*)$ secret/recipelookup.php?search=$1 [L,QSA]
RewriteRule ^api/json/idbyname/(.*)$ api/json/getidbyname.php?id=$1 [QSA,L]
RewriteRule ^api/csv/idbyname/(.*)$ api/csv/getidbyname.php?id=$1 [QSA,L]
RewriteRule ^api/json/item/(.*)$ api/json/items.php?id=$1 [QSA,L]
RewriteRule ^api/csv/item/(.*)$ api/csv/items.php?id=$1 [QSA,L]
RewriteRule ^api/json/forge/(.*)$ api/json/mysticforge.php?id=$1 [QSA,L]
RewriteRule ^api/csv/forge/(.*)$ api/csv/mysticforge.php?id=$1 [QSA,L]
RewriteRule ^api/json/history/(.*)$ api/json/tradehistory.php?id=$1 [QSA,L]
RewriteRule ^api/csv/history/(.*)$ api/csv/tradehistory.php?id=$1 [QSA,L]
RewriteRule ^api/json/history-daily/(.*)$ api/json/tradehistorydaily.php?id=$1 [QSA,L]
RewriteRule ^api/csv/history-daily/(.*)$ api/csv/tradehistorydaily.php?id=$1 [QSA,L]
RewriteRule ^api/json/recipe/(.*)$ api/json/craftingrecipes.php?id=$1 [QSA,L]
RewriteRule ^api/csv/recipe/(.*)$ api/csv/craftingrecipes.php?id=$1 [QSA,L]
RewriteRule ^api/json/exchange/(.*)$ api/json/gemexchange.php [QSA,L]
RewriteRule ^api/csv/exchange/(.*)$ api/csv/gemexchange.php [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

#Gzip Compression, Saves on bandwidth
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript application/vnd.ms-fontobject application/x-font-ttf image/svg+xml
</ifmodule>
#End Gzip