Search code examples
htmlvariableshttp-status-code-404

Need to add the requested URL on a "404"-page. [HTML]


If the user tries to access a page which isn't available, he/she is moved to a custom 404.html.

What I'm wondering is if is it possible to access the original requested URL from the custom 404.html, using just HTML? I haven't used PhP or any other side technology.

My code look like this:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

If anyone know how do this, please let me know. Thank you in advance!


Solution

  • Long story short, answer to your question: no, it is not possible to get url by using HTML ONLY, you need to either use client side or server side language.

    for example, in javascript, you would do something like this to get previous url,

    document.referrer
    

    this would actually be ideal for your scenario, as this work very well, if you arrived at the current page via a link ( not by doing, for example, by bookmark or typing in the address bar).