customize error page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Alicia
New php-forum User
New php-forum User
Posts: 94
Joined: Sun Sep 21, 2003 5:30 pm

customize error page

Postby Alicia » Sun Nov 23, 2003 10:44 pm

Hi guys,

i am wondering is it possible for us to do our own customise error page message with our own contents.

e.g: my webpage url is http://www.myweb.com

when the user try to access http://www.myweb.com/dunno.htm.. or kodasda.htm and etc

if the file doesn't exist in my server, is it possible for me to output my own contents like "The page you are trying to access is not valid. Please go to our site map" rather than the default contents show on the browser - Page Not Found..


or I must have a file in order to display my own contents ?

please advise.

User avatar
mammal
New php-forum User
New php-forum User
Posts: 37
Joined: Wed Apr 02, 2003 1:31 am
Location: Hythe, UK

Postby mammal » Mon Nov 24, 2003 1:05 am

Try this link, you need a server file to create custom 404 page not found pages.

http://www.icthus.net/CGI-City/tut_htaccess4.shtml

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Apache...

Postby ruturajv » Mon Nov 24, 2003 5:32 am

In Apache try putting the following in the .htaccess file

Code: Select all

ErrorDocument 404 "http://yourdomain.com/404errpage.htm"

Alicia
New php-forum User
New php-forum User
Posts: 94
Joined: Sun Sep 21, 2003 5:30 pm

Postby Alicia » Wed Nov 26, 2003 5:37 pm

Thanks for your info,, but how can i create a .htaccess file and upload there ?

I am not able to download the .htaccess file in my folder.. it is 0kb..


please advise.

Alicia
New php-forum User
New php-forum User
Posts: 94
Joined: Sun Sep 21, 2003 5:30 pm

Postby Alicia » Wed Nov 26, 2003 6:11 pm

I have added this line in my htaccess file but why it still doesn't work ? It still shows the default page...

ErrorDocument 404 "http://62.129.238.22/~myweb/affiliate/notfound.htm"


Did i miss something ? Please advise.

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Wed Nov 26, 2003 6:15 pm

you can also go another route....

for example have a link creating function like

function makeLink($link,$text){
if(file_exists($link)) echo "<a href=\"".$link."\">".$text."</a>";
else echo "<a href=\"error.php?page=".$link."\">".$text."</a>";
}

and in your code

<p>fejkefdijewdo ijeooef <? makeLink("page.html","text") ?> deokwdokwpekodpoked </p>

where the error.php would display some kind of page.html is not available..... hope that gives you an idea..... :wink:

Alicia
New php-forum User
New php-forum User
Posts: 94
Joined: Sun Sep 21, 2003 5:30 pm

Postby Alicia » Wed Nov 26, 2003 8:02 pm

I dun really get what you mean ? what you said doesn't seem related to htaccess am i right ?

i was told using htaccess is easier than using other methods.. please advise...

User avatar
pio
New php-forum User
New php-forum User
Posts: 12
Joined: Sat Nov 29, 2003 9:58 am
Location: Oslo, Norway
Contact:

clever...!

Postby pio » Sat Nov 29, 2003 11:53 am

liquedus' little function is pure genius! (why didn't I think of it first? :cry: )

No, it doesn't have ANYTHING to do with .htaccess, but you avoid the hassle that changing .htaccess can be if you're not running your own server.

you replace all your links with <? makeLink("page.html","link text") ?>, and the function checks if the link is valid. if not, it replaces the link with a link to the error page using the same link text.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest