Mobile app version of vmapp.org
Login or Join
Angela700

: Can html go in the ErrorDocument value internally in httpd.conf? According to apache documentation, the final parameter of ErrorDocument can be specified as a path, URL or text to any error code.

@Angela700

Posted in: #Apache #Error #Html

According to apache documentation, the final parameter of ErrorDocument can be specified as a path, URL or text to any error code.

What I have done so far to eliminate any calls to the I/O file system is to use text as my final value. For example, I use the following in my httpd.conf file:

ErrorDocument 404 "Error: Not Found"


And of course when I restart apache and a user requests a file not being found, they only see "Error: Not found" on the screen.

All is well until I trigger the error in Google's page-speed insights.

Here's the URL to the test:
developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fthenew.clubcatcher.com%2Fpictures%2Fnotexist
Pagespeed tells me to configure the viewport and to use legible font sizes.

I personally think its an overkill considering that I made the size of the error pages so small to prevent bots from sucking up my bandwidth, and now it seems the solution is to add a 1000% byte increase per error triggered just to make google happy. (That's right, I'd have to go from 50 or so bytes to over 500).

I could rant more, but what I'm considering to make everyone happy is to format my error pages to contain HTML but without the need of accessing the file system. For example, I want to include something like this in my httpd.conf:

ErrorDocument 404 '<html><head><meta name="viewport" content="width:device-width"></head><body>Not found</body></html>'


Such HTML would make the page more compatible with mobile users, but the question is, would apache accept html as text? and if so, how do I rearrange it in the best form so that apache outputs it as raw html so that the browser converts the data correctly for the client? I ask that because my value has quotes in it and I don't want apache thrown off.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela700

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

Can html go in the ErrorDocument value internally in httpd.conf?


Yes.

HTML is just text and Apache appears to send this with a Content-Type: text/html header by default anyway. So, when this "text" hits the browser the browser renders it as HTML, even when sending a simple string of text.


...would apache accept html as text?


As stated above, HTML is text. It's up to the browser to do something with it (providing it knows what to do with it).


how do I rearrange it in the best form so that apache outputs it as raw html


What you already have looks good to go.


because my value has quotes in it and I don't want apache thrown off.


The argument passed to the ErrorDocument directive needs to be delimited by quotes (either double or single) for it to be interpreted as text.

If your text contains the same quotes you are using to delimit your text (eg. using double quotes in a string surrounded by double quotes) then these must be backslash escaped. eg. "<meta name="viewport" content...". However, don't escape quotes when they don't need to be (eg. double quotes in a single quoted string), otherwise the backslash is simply seen as a literal backslash.

Using single quotes to delimit HTML would seem to be the best option for this reason. (Assuming double quotes are used for attribute values.)

If Apache does get "thrown off" you'll likely get a 500 error - so you'll know very quickly that something is off!

Just a thought, to make it readable on the small screen you could just use an h1 tag, rather than a full/compliant document? (Does Google Pagespeed recognise this?)

ErrorDocument 404 "<h1>Error: Not Found</h1>"



eliminate any calls to the I/O file system


However, I do kinda wonder whether this really makes any difference?!

A verbose 404 with helpful information and links for the user is an opportunity to keep the user on your site and stop them from bouncing. This might be more important than the file I/Os and extra bandwidth that a bot might consume. (?)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme