duan5991518 2015-06-26 23:41
浏览 49
已采纳

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条回答 默认 最新

  • dsp1836 2015-06-27 06:18
    关注
    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条