ErrorDocument 404指令不适用于Heroku

时间:2014-08-02 15:00:38

标签: php heroku apache2 http-status-code-404

我正在尝试在Heroku上托管的网站中捕获404错误,但它似乎无法正常工作。 我使用ErrorDocument 404 /404.php但是在尝试访问不存在的页面时,如

http://myapp.herokuapp.com/asdfasdf

它显示纯文本:“找不到文件”而不是我的自定义404.php页面。

我知道我的Dyno运行Apache 2.默认情况下,AllowOverride设置为All,其余指令正常运行。我根本看不到这个错误。

这是我的整个.htaccess:

#
# Allow access to .php files without specifying extension in url
# From: http://stackoverflow.com/questions/8371634/hide-php-extension-htaccess
#
RewriteEngine On

# Important to some servers
RewriteBase /

# Redirect requests starting with www to non-www url
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ ./$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ ./$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

#Set 400 error page
ErrorDocument 404 /404.php

# Set soon.php as default homepage
DirectoryIndex /soon.php

修改

访问不存在的页面后运行“heroku logs”命令可以提供更多信息:

←[35m2014-08-02T15:24:17.976010+00:00 heroku[router]:←[0m at=info method=GET pat
h="/asdfasdf" host=myapp.herokuapp.com request_id=33cadc8b-cc4b-423b-b834-aed
d55e16a6c fwd="83.53.204.212" dyno=web.1 connect=0ms service=5ms status=404 byte
s=629
←[36m2014-08-02T15:24:18.296967+00:00 app[web.1]:←[0m 10.238.166.109 - - [02/Aug
/2014:15:24:17 +0000] "GET /asdfasdf HTTP/1.1" 404 16 "-" "Mozilla/5.0 (Windows
NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.3
6"
←[36m2014-08-02T15:24:18.296977+00:00 app[web.1]:←[0m [Sat Aug 02 15:24:17.97446
9 2014] [proxy_fcgi:error] [pid 67:tid 140458089158400] [client 10.238.166.109:5
5877] AH01071: Got error 'Primary script unknown\n'

这个模糊的“[proxy_fcgi:error]”可能表示此错误与其他已知的Heroku问题有某种关联:https://github.com/heroku/heroku-buildpack-php/issues/46

0 个答案:

没有答案