preventing from a use to get to a 404 page

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

preventing from a use to get to a 404 page

Post by pelegk2 »

i am running php over apache
is there a way to prevent from a user from hetting to unexisting page?
for exampl
if the user type by mistake :
page1.ph
instead of page1.php
i want him in this case to go to a certin page!
how do i do that?
thanks in advance
peleg
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i'm assuming you are using Apache..

Create a file called .htaccess in the root directory of the server (the one you refer to as '/') and enter your error handlers in the following format, one per line:


ErrorDocument [3-digit code] [action]
For example, you can point to a custom 404 page like this:


ErrorDocument 404 /errors/custom404.html
You can also simply have it display some other text:


ErrorDocument 404 "Sorry, this page doesn't exist.
Make sure you begin the text with a quote (").

Windows users have reported problems creating .htaccess files. Create a file named 'htaccess.txt', FTP it to your web host, and then rename it to .htaccess.

You can even make your 404 errors more friendly for international visitors by displaying a page in their own language. Check out this Apache article.


Just make sure you create a 404.htm page that tells the user the page could not be found,a nd then insert it as described above.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

ok i understood almost everythin

Post by pelegk2 »

i didnt execlly understand ho to call execlly the file name?
the apache server it on my pc so i dont have poblem to access it
so how execly do i call the fil "htaccess'" the exclly file name?
thanks alot
peleg
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You just drop the file in the directory you want to configure. It's not a filename by the way since it's not -> .htaccess.txt. Be careful when you save, if you use notepad, when saving put file type to "all files".

-Nay
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

i dint know why it isnt working

Post by pelegk2 »

i hae opened a file called :

Code: Select all

<?php
.htaccess
?>
then i wrote in it :

Code: Select all

<?php
ErrorDocument 404 "Sorry, this page doesn't exist. 

?>
and still nothin
and even estarted the derver
and putted the file in the root
any idea?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

i even tried to make changes at

Post by pelegk2 »

conf/httpd.conf
and it didnt help:(
what to do??
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Peleg,

Open notepad.
Paste these 4 lines in it:

ErrorDocument 500 /error.htm
ErrorDocument 404 /error.htm
ErrorDocument 401 /error.htm
ErrorDocument 403 /error.htm

Select File, Save as
Select All files in the Save file dialog box.
Type .htaccess and press the save button.
Upload the .htaccess file to the root folder of your webserver.
Create a file called error.htm and upload this in the root folder of your webserver.

Call a file that doesn't exist and it should show the content of your self made error.htm

Hope this helps you.

Greetz Jolly.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

still isnt working

Post by pelegk2 »

maybe something else ineed to define to so i will work?
Post Reply