/    Sign up×
Community /Pin to ProfileBookmark

NOT FOUND – how to prevent

I have a situation. When a user accesses a wrong link an error message shows up:

Not Found

The requested URL /hello was not found on this server.

For example: [url]www.mywebsite.com/hello[/url]

Where hello does not exists in the server.

I would like to show a message “OOPS! Requested page does not exists. Please try again!”

Can I do this in PHP?

Thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Dec 18.2009 — You can add your custom error handler in your server configuration. In apache it is the errorhandler directive. I'm not sure what it is in IIS and others.
Copy linkTweet thisAlerts:
@codingisfunauthorDec 18.2009 — I have a apache2 server.
Copy linkTweet thisAlerts:
@NogDogDec 18.2009 — .htaccess:
<i>
</i>ErrorDocument 404 /path/to/custom_404.php

(Note that "/path..." above starts from the web document root, not the local disk root. Do not use a "http://..." URL.)

In your custom 404 PHP file you can use [B]$_SERVER['URI_REQUEST'][/B] to reference the page that the user had requested.
×

Success!

Help @codingisfun 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.23,
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,
)...