Take the 2-minute tour ×

I suspect this can't be done, but here goes anyway. Is there a way, on a static site, to show the URL the user is trying to reach when you use the Apache directive ErrorDocument to redirect a 404 File Not Found error to a custom page? For instance, if you try:


the default 404 error says:

The requested URL /dingbat/arsebiscuits was not found on this server.

So the URL must be in an environment variable. Can I get at that in a custom error document? I'd like to tell users the URL rather than just give them a generic error document. I know I can do this easily enough in PHP, but the site comprises static HTML docs only.

share|improve this question
Having a static site does not prevent you from having a dynamic error page. Does your hosting service offer some kind of server-side technology? –  Álvaro G. Vicario Jan 3 '13 at 16:14
Thanks, Álvaro. PHP is fine on the hosting service (Titan), so I suppose that I could write a PHP script for the 404. Probably REQUEST_URI (php.net/manual/en/reserved.variables.server.php) would be the best environment variable to use unless you could suggest a better approach? Although the site (fredriley.org.uk/callhull) is primarily comprised of static docs I do use a couple of PHP scripts on it for forms so it would be no big to write another. I'm curious, though, if there's a way to access env vars in a static HTML doc. –  Fred Riley Jan 3 '13 at 16:53
Static means that: static ;-) I've written a proper answer for the rest. –  Álvaro G. Vicario Jan 3 '13 at 17:08
add comment

1 Answer

Having a static site does not prevent you from having a dynamic error page. You can use whatever server-side technology your hosting service offers.

If you can use PHP, you can simply pick a static template, change its extension to *.php and add a little dynamic snippet:

<p><?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?></p>

If you can use SSI, it's very similar:

<p><!--#echo var="REQUEST_URI" --></span></p>

The REQUEST_URI variable contains the local part of the URL as typed by the user (except hash). It's a good choice.

share|improve this answer
Thanks. I'd completely forgotten about SSI, it being relatively rare these days and unsupported by many hosts. –  Fred Riley Jan 3 '13 at 19:15
add comment

Your Answer


