You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by David Wakelin <da...@aplpackaging.co.uk> on 2018/07/09 13:49:23 UTC

[users@httpd] Can I return a 404 for a file that is also the ErrorDocument?

I have created a file 404.html to act as my 404 page that is returned by
ErrorDocument:

ErrorDocument 404 /404.html

This works fine, except when accessing 404.html directly, which returns a
status code of 200

I've attempted a RewriteRule like so:

ErrorDocument 404 /404.html
RewriteRule "404\.html" - [R=404]

However, this now returns an error instead of my 404.html doc:

The requested URL /does-not-exist.html was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.

How can I return a status of 404 for the 404.html document itself?

I have seen solutions using PHP, but I am *NOT* using PHP and have no means
to do so (I don't use mpm_prefork and I will not setup and run php-fpm just
for a status code header)
Kind Regards

David Wakelin



www.aplpackaging.co.uk   david@aplpackaging.co.uk   01903 202 333

Re: [users@httpd] Can I return a 404 for a file that is also the ErrorDocument?

Posted by John <jo...@iliffe.ca>.
I may be missing something here but in the case where 404.html is directly
requested as /404.html, the 200 is the correct response code because the file
was found and served.  404 means that the file was not found.
regards,
John======================================On Mon, 2018-07-09 at 10:33 -0400,
Eric Covener wrote:
> On Mon, Jul 9, 2018 at 9:49 AM David Wakelin <da...@aplpackaging.co.uk> wrote:
> > I have created a file 404.html to act as my 404 page that is returned
> > by ErrorDocument:
> > ErrorDocument 404 /404.html
> > This works fine, except when accessing 404.html directly, which returns a
> > status code of 200
> > I've attempted a RewriteRule like so:
> > ErrorDocument 404 /404.html
> > RewriteRule "404\.html" - [R=404]
> > However, this now returns an error instead of my 404.html doc:
> > The requested URL /does-not-exist.html was not found on this server.
> > Additionally, a 404 Not Found error was encountered while trying to use an
> > ErrorDocument to handle the request.
> > How can I return a status of 404 for the 404.html document itself?
> > I have seen solutions using PHP, but I am NOT using PHP and have no means to
> > do so (I don't use mpm_prefork and I will not setup and run php-fpm just for
> > a status code header)
> > Kind Regards
> > 
> > 
> > David Wakelin
> > 
> > 
> > 
> > 
> > 
> > www.aplpackaging.co.uk   david@aplpackaging.co.uk   01903 202 333
> 
> 
> You could try checking the REDIRECT_STATUS per-request environment variable to
> try to determine if it's being accessed directly.  
> Or maybe in mod_rewrite check %{THE_REQUEST} for /404.html -- I think this
> won't change as a result of internal redirects, error pages, etc.
> 
> 
> 

Re: [users@httpd] Can I return a 404 for a file that is also the ErrorDocument?

Posted by Eric Covener <co...@gmail.com>.
On Mon, Jul 9, 2018 at 9:49 AM David Wakelin <da...@aplpackaging.co.uk>
wrote:

> I have created a file 404.html to act as my 404 page that is returned by
> ErrorDocument:
>
> ErrorDocument 404 /404.html
>
> This works fine, except when accessing 404.html directly, which returns a
> status code of 200
>
> I've attempted a RewriteRule like so:
>
> ErrorDocument 404 /404.html
> RewriteRule "404\.html" - [R=404]
>
> However, this now returns an error instead of my 404.html doc:
>
> The requested URL /does-not-exist.html was not found on this server.
> Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
>
> How can I return a status of 404 for the 404.html document itself?
>
> I have seen solutions using PHP, but I am *NOT* using PHP and have no
> means to do so (I don't use mpm_prefork and I will not setup and run
> php-fpm just for a status code header)
> Kind Regards
>
> David Wakelin
>
>
>
> www.aplpackaging.co.uk   david@aplpackaging.co.uk   01903 202 333
>
​
You could try checking the REDIRECT_STATUS per-request environment variable
to try to determine if it's being accessed directly.
Or maybe in mod_rewrite check %{THE_REQUEST}​ for /404.html -- I think this
won't change as a result of internal redirects, error pages, etc.



-- 
Eric Covener
covener@gmail.com