# Custom 404 error message [solved]

## iplayfast

I'm trying to create a custom php error message, and from what I've read, the proper way to do this is create an .htaccess file containing:

ErrorDocument 404 missing.php

where missing.php is my custom message.

When I do this, the page comes back with the text

missing.php

This happens whether it's php or html.

Does anyone know how to get apache to actually send back the page instead of just displaying the name of it?

TIALast edited by iplayfast on Tue Jan 02, 2007 2:49 pm; edited 1 time in total

----------

## bunder

 *apache core features page wrote:*   

> URLs can begin with a slash (/) for local URLs, or be a full URL which the client can resolve. Examples:
> 
>     ErrorDocument 500 http://foo.example.com/cgi-bin/tester
> 
>     ErrorDocument 404 /cgi-bin/bad_urls.pl
> ...

 

try adding a leading slash.

cheers

----------

## iplayfast

I did try that, but then it complains that it can't find the missing.php file.

I also tried putting the filename in quotes (no difference).

I think it's finding the file, but it isn't returning the contents. It's just displaying the name.

----------

## bunder

 *iplayfast wrote:*   

> I did try that, but then it complains that it can't find the missing.php file.
> 
> I also tried putting the filename in quotes (no difference).
> 
> I think it's finding the file, but it isn't returning the contents. It's just displaying the name.

 

is the file in your webroot?  if you use /missing.php and its not in the webroot, it will fail.  try checking /var/log/apache/error_log.

----------

## iplayfast

Yes the file is there. If I rename it, I get a different error message saying it can't find the file.

putting a / in front gives

```
The requested URL /~stockchase/Expert-sl--q-ID-v--Paul-VanEeden.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

```

putting ~/ in front of it gives

```

~/missing.php

```

----------

## jasonpf

I hope I'm not beating a dead horse here, but just to make sure that there was no misunderstanding in a previous posters message (or maybe I misunderstood).

The ErrorDocument directive does not accept relative URLs.  For instance, if you had a URL as:  http://www.test.com/thisisatest/dir1/index.html  and had an htaccess file such as http://www.test.com/thisisatest/dir1/.htaccess  with the following contents:

```
ErrorDocument 404 /missing.php
```

Then it would try to redirect to:

```
http://www.test.com/missing.php
```

and NOT

```
http://www.test.com/thisisatest/dir1/missing.php
```

The only way around that is to 1) Perhaps look into a mod_alias redirect to do some fancy URL rewriting, which is beyond me without a lot of research/testing  or 2) use the full URL in the "ErrorDocument" statement, such as:

```
ErrorDocument 404 http://www.test.com/thisisatest/dir1/missing.php
```

That should work.  Another option is to create the missing.php file in the root of the site (http://www.test.com/missing.php) and then reference it via my first code snipet (...404 /missing.php).  You could have multiple files in the root like missing1.php missing2.php and reference a different one depending on the contents of the .htaccess file.  Or you could create a directory called 404docs in the root and use:

```
ErrorDocument 404 /404docs/missing1.php
```

to reference the following error document:

```
http://www.test.com/404docs/missing1.php
```

I hope this helps and doesn't over-confuse the issue.

----------

## iplayfast

Yes I think you are beating a dead horse there.  :Sad: 

The webroot is at 

\home\stockchase\public_html

The missing.php is at

\home\stockchase\public_html\missing.php

It is finding the document and displaying the document name, instead of running it. (Which would do some fancy stuff to go to other directories and things).

----------

## DoktorSeven

From what I see, you're using a home/public_html, and you want an error document within that.

As stated, /missing.php gets you at the true web root, and a public_html places your document in /~username/ which is NOT the web root.

Therefore what you need is

ErrorDocument 404 /~stockchase/missing.php

----------

## iplayfast

Excellent, that seemed to get it. (now to debug missing.php)

Thank you so much.

----------

