LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-26-2012, 02:30 AM   #1
gozlemci
Member
 
Registered: Mar 2010
Location: Turkey
Distribution: Ubuntu 12.04
Posts: 34

Rep: Reputation: 0
how to handle broken links in HTML


Hi there;
When I implement a web site, I would like to handle the broken links and put relevant HTML file. For example, when the visitor tries to reach non-existent link actually :

www.mysite.com/non_existent_file.html

I would like to handle this request. How?

Thanks.
 
Old 01-26-2012, 04:37 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 207Reputation: 207Reputation: 207
You could check to see if the target exists with a rewrite rule, and redirect appropriately.

Something like this:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ /handler.php [L,R=301]
 
1 members found this post helpful.
Old 01-26-2012, 01:26 PM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
If you are using Apache, I'd recommend setting a ErrorDocument 404 /local/url/to/script instead. The custom error handler script receives all pertinent information about the failed request or missing page.

The trickiest implementation of a 404 (Not found) error handler I know (not currently used in production, though) tries a number of alternate servers to locate the corresponding page. Very useful when migrating and combining web servers.
 
1 members found this post helpful.
Old 01-27-2012, 12:54 AM   #4
gozlemci
Member
 
Registered: Mar 2010
Location: Turkey
Distribution: Ubuntu 12.04
Posts: 34

Original Poster
Rep: Reputation: 0
Thank you for the replies. Unfortunately my firm enforce me to use IIS.
 
Old 01-27-2012, 12:20 PM   #5
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by gozlemci View Post
Thank you for the replies. Unfortunately my firm enforce me to use IIS.
In that case, you must consult IIS documentation. This is an IIS configuration issue, not a programming problem.
 
  


Reply

Tags
broken, html


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
clicking on links in thunderbird e-mails, firefox can't handle php scripts mbvpixies78 Linux - Software 11 01-02-2008 09:44 AM
DHCP-3.0.5 links broken Paulsuk Linux From Scratch 2 12-03-2007 11:32 PM
Broken simbolic links ale_murakami Amigo 2 05-20-2005 06:06 AM
Broken links? danthehat Linux - Newbie 4 02-03-2005 03:06 PM
Konqueror and broken links lachlan Linux - Software 0 07-29-2002 09:23 PM


All times are GMT -5. The time now is 07:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration