Bad Link Notify

  • Thread starter Dennis M. Marks
  • Start date
D

Dennis M. Marks

Is there a graceful way to trap a bad link on your page and display a
message to the user when he clicks it?

I don't like the generic "The specified server cound not be found".

What if the server exists but the page doesn't. Can I keep the server
from gaining control and displaying its message that the page can't be
found?
 
D

Dylan Parry

Dennis said:
Is there a graceful way to trap a bad link on your page and display a
message to the user when he clicks it?

I don't like the generic "The specified server cound not be found".

What if the server exists but the page doesn't. Can I keep the server
from gaining control and displaying its message that the page can't be
found?

Yes. If your server is Apache, then you can use .htaccess files to do this.

Simply create a file called .htaccess in the root directory of your
webspace, and in that file type:

ErrorDocument 404 /404.html

Then create the file 404.html in the root directory of your webspace. Now
whenever someone types a url for a page that doesn't exist on your site
they will see the contents of 404.html instead of the default Apache error
message.

HTH
 
B

brucie

Is there a graceful way to trap a bad link on your page and display a
message to the user when he clicks it?

you shouldn't have any bad internal links although you should still
setup your error documents. for external links use a link verification
script to delete the link from your pages if its bad (no point having it
on your pages if its bad)
 
T

Toby A Inkster

Dennis said:
Is there a graceful way to trap a bad link on your page and display a
message to the user when he clicks it?

You can display a customised 404 error for bad links to pages on your own
site -- see Dylan's post.
What if the server exists but the page doesn't. Can I keep the server
from gaining control and displaying its message that the page can't be
found?

No you can't. Once someone has clicked a link, they're off your page and
what happens to them is entirely beyond your power.
 
K

kayodeok

for external links use a link verification
script to delete the link from your pages if its bad (no point
having it on your pages if its bad)

Brucie

Would you mind expanding on this link verification script? It's the
first time I am hearing of it.
 
B

brucie

Would you mind expanding on this link verification script?

l i n k v e r i f i c a t i o n s c r i p t
It's the first time I am hearing of it.

i really don't know what to tell you, they're just scripts that check to
see if a link is valid (e.g. returning a 200 on a HEAD) and if not
perform some action. theres all sorts of different types.

http://www.google.com/search?q=link+checking+script&num=50
http://www.google.com/search?q=link+verification+script&num=50

http://www.hotscripts.com/PHP/Scripts_and_Programs/Link_Checking/index.html
http://www.hotscripts.com/Perl/Scripts_and_Programs/Link_Checking/index.html
 
K

kayodeok


Thanks, I know about those.

At the time I read Brucie's post to Dennis M Marks, I had just got
out of bed and I misintepreted his post to mean that if a user clicks
an external link that had gone bad, it would show up in the
webmaster's log (which I know is not possible) and at the same time,
the link will be removed from the webmaster's pages...of course, this
was before my first coffee and I can see that isn't what he meant.
 
K

kayodeok

in post <kayodeok said:
i really don't know what to tell you, they're just scripts that
check to see if a link is valid (e.g. returning a 200 on a HEAD)
and if not perform some action. theres all sorts of different
types.

[snipped some nice links]

Thanks, I know what you mean now, I think I am having one of those
slow days when everything turns into a blur (you can see my reply to
Toby to see what I mean)
 
T

Toby A Inkster

kayodeok said:
At the time I read Brucie's post to Dennis M Marks, I had just got
out of bed and I misintepreted his post to mean that if a user clicks
an external link that had gone bad, it would show up in the
webmaster's log (which I know is not possible) and at the same time,
the link will be removed from the webmaster's pages...

It would certainly be possible to set up something nice like this.

Go through all your pages and replace:

<a href="http://example.org/some_external_link/">foo</a>

with:

<a href="/external?http://example.org/some_external_link/">foo</a>

where "/external" is a CGI/PHP/whatever script that does the following:

1. Look at the query string and extract the URL.

2. Issue an HTTP 'HEAD' request for the URL.

3. If the response code is less than 200 or greater than 399,
jump to step 6.

4. Redirect the user to the URL.

5. Jump to step 8.

6. E-mail the URL and response code to yourself.

7. Output a pretty error message to the visitor explaining why
the link doesn't work and offering a link back to the page
they've just come from (you could use the query string or
the HTTP 'Referer' header for this!)

8. Script ends.

(My pseudo code is full of GOTOs. Naughty me.)

Could actually be quite a nice system. The only real problem is that when
the visitor hovers your external links he won't see the proper URL, but
this could be added to @title, or even replaced using ECMAscripting.
 
K

kayodeok

kayodeok said:
At the time I read Brucie's post to Dennis M Marks, I had just
got out of bed and I misintepreted his post to mean that if a
user clicks an external link that had gone bad, it would show
up in the webmaster's log (which I know is not possible) and at
the same time, the link will be removed from the webmaster's
pages...

It would certainly be possible to set up something nice like
this.

Go through all your pages and replace:

<a href="http://example.org/some_external_link/">foo</a>

with:

<a
href="/external?http://example.org/some_external_link/">foo<
/a>

where "/external" is a CGI/PHP/whatever script that does the
following:

[snipped rest of code for brevity]

Thanks!
Much appreciated and I have saved the post for future reference.

Regards
 
E

Eric Bohlman

where "/external" is a CGI/PHP/whatever script that does the following:

1. Look at the query string and extract the URL.

2. Issue an HTTP 'HEAD' request for the URL.

3. If the response code is less than 200 or greater than 399,
jump to step 6.

Only problem here is that some servers won't honor HEAD requests,
particularly if the URL in question is for something dynamically generated.
So if a HEAD fails, you really have to try a GET before giving up.
 
N

Nico Schuyt

Dennis said:
Is there a graceful way to trap a bad link on your page and display a
message to the user when he clicks it?
I don't like the generic "The specified server cound not be found".
What if the server exists but the page doesn't. Can I keep the server
from gaining control and displaying its message that the page can't be
found?

Some editors (like FP :) can check for broken links. Otherwise check the
links with http://validator.w3.org/checklink

For internal URL's that are no longer valid (but still found in an SE) or
typos:
Ask your host to create a 404 redirect to an error page.
Example: http://www.nicoschuyt.nl/xxxxxxx.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,247
Latest member
GabrieleL2

Latest Threads

Top