/    Sign up×
Community /Pin to ProfileBookmark

n00bish JS link editing Question

[b]Some Background First[/b]: On a website, I have a custom 404 error page via .htaccess, nothing special.

[b]The Problem[/b]: That page happens to be appearing far too much

[b]The Reason[/b]: The URL Frame automatically generated by the server (a URL Frame allows an input URL through a link or a browser location bar in the form [url]http://site.com/whatever[/url] , which opens the real URL location in an invisible frame: [url]http://realsite.com/site.com/whatever[/url] . Of course the site.com form looks far better than giving the actual URL, and is shorter too, so it;s much easier for the user to use it and type it.) doesn’t work very well and often fails. It just so happens that you never see 404s if you enter in the real URL.

[b]The Compromise[/b]: I really don’t want to link to the real URL, so I decided whenever a 404 comes up, the user can just click on a link to the real URL and they will be where they want to go.

[b]The Solution[/b]: I was thinking that maybe if I could get some JavaScript on the 404 page to read the referrer URL (i.e. in [url]http://site.com/whatever/[/url] form) and alter it to the real URL, which it displays as a link, “were you trying to go here?”

[b]The… Other Problem[/b]: I stink at JS and have no idea how. I was told this would be a pretty simple script, but I can’t do it.

Can somebody give me a hand?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@DrDaMourApr 25.2003 — this shoudl work for you, modify the URLS



<script>

if("badurl" == window.location){

document.wirte("Since you tried to go to " + window.location + " I'm sending you to URLTOGOTO");

window.location.href = "urltogoto";

}


</script>
Copy linkTweet thisAlerts:
@SDaddyauthorApr 25.2003 — Hmm... but what I want is for the 404 page to read the URL of the page that didn't work which sends the user to the 404 page (http://site.com/whatever) and write on the 404 page a link to http://realsite.com/site/whatever

So in other words, it has to read the referrer's URL, and output the proper URL. Is this easily possible?
Copy linkTweet thisAlerts:
@SDaddyauthorApr 26.2003 — bump ?
Copy linkTweet thisAlerts:
@khalidali63Apr 26.2003 — There are some apprehensions about the

referrer method.It is webserver depenedent.And it does not work for all the time.

The best that I can think of is you pass the error originating pages url to the 404 response page...adn on that page parse the url and then create a link ...etc..

Make any sense?
×

Success!

Help @SDaddy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...