Need to avoid redirect to webhost homepage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Need to avoid redirect to webhost homepage

Post by drayarms »

Hello, I never really gave a serious thought to the above question until now that I'm trying to actually launch a live site. Well I'm sure most of you are familiar with this situation, where a user my enter a wrong, non existent url, whose root happens to be your domain name. For example, instead of entering domain.com/greetings, the user may wrongly type domain.com/grewtings . How can I make my site to redirect such erroneous urls to my homepage, instead of to my webhost's homepage with an error message?

Appreciate all answers.
User avatar
Tiancris
Forum Commoner
Posts: 39
Joined: Sun Jan 08, 2012 9:54 pm
Location: Mar del Plata, Argentina

Re: Need to avoid redirect to webhost homepage

Post by Tiancris »

If you have an htaccess file, then add the following line:

ErrorDocument 404 /index.php

or may be redirect to an error page:

ErrorDocument 404 /error.php

Thus, for any invalid access, the visitor will be redirected to the specified page.
Post Reply