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?

thanks

bael

3 answers

2
points

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 almost 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 almost 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 almost 7 years ago
1
point

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. -->
<? $_SERVER['REQUEST_URI'] ?>

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

Answered almost 7 years ago by Matthew Kimber
1
point

You can also try the document.referrer property.

Answered almost 7 years ago by Nathan DeGruchy