Jason 14

Hi All,

How would I go about creating a 404 page that actually knows what url they tried to go to?

For example, if I go to http://www.samplesite.com/thispagedoesnotexist.html, i will get a 404 page. I want this 404 page to display the above url as text in the browser.

Is this possible? Jscript? Javascript?



3 answers


In Javascript, you can call window.location.href to retrieve the browser's current URL as long as you aren't redirecting to a static 404 page url. (e.g. http://www.samplesite.com/404.html)

Answered about 7 years ago by Lucas Willett
  • So when the user hits the 404 page, i won't be able to display the intended url on the 404 page? Jason about 7 years ago
  • You can set a specific page to be a handler for that error code. This won't redirect them to the page's URL, but it will show the error page as intended. Lucas Willett about 7 years ago

You can also accomplish this on the backend by looking at the server variables through ASP.net, PHP, et al.

<!-- php code to get the requested url. -->

This code will simply right out the requested url into your html.

Answered about 7 years ago by Matthew Kimber

You can also try the document.referrer property.

Answered about 7 years ago by Nathan DeGruchy