1

I'm trying catch 404 errors in my website hosted on Heroku but it doesn't seem to work. I using ErrorDocument 404 /404.php but when trying to access a non-existant page like

http://myapp.herokuapp.com/asdfasdf

It shows a plain text: "File not found" instead of my custom 404.php page.

I know my Dyno runs Apache 2. AllowOverride is set to All by default and the rest of the directives are working ok. I simply can't see the bug.

This is my whole .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

EDIT

Running "heroku logs" command after visiting a non-existant page gives some more information:

←[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'

That obscure "[proxy_fcgi:error]" may indicate that this error is somehow related to this other known Heroku issue: https://github.com/heroku/heroku-buildpack-php/issues/46

0 Answers0