Koozali.org: home of the SME Server

custom 404 error page

Paul Wolsink

custom 404 error page
« on: April 20, 2003, 04:27:08 AM »
Hi there
How does one create 404 error pages and get it to work on sme 5.5/5.6?
I've tried everything (.htaccess as well as in the httpd.conf) and nothing seems to work the way as described in the apache manuals.

Any advise
Thanks
Paul

Chris

Re: custom 404 error page
« Reply #1 on: April 20, 2003, 05:30:34 PM »
.htaccess is not enabled by default. Do a search on how to turn it on

Greg

Re: custom 404 error page
« Reply #2 on: April 20, 2003, 06:17:41 PM »
Hello Paul

I had the same head ache. Check out this link. It solved my problems and gave the solution nice and simple for a newbie :-)

http://www.yourhtmlsource.com/accessibility/custom404error.html

Greg

Roger

Re: custom 404 error page
« Reply #3 on: April 22, 2003, 09:04:34 AM »
Just (finally) got my custom error pages working ..

Had to:
1) enable htaccess .. downloaded RMP from http://mirror.contribs.org/smeserver/contribs/nightspirit/e-smith-htaccess/ (for SME Server 5.6) and installed it using >rpm -ivh *.rpm

2) created .htaccess with contents:
ErrorDocument 400/error.php?error=400
ErrorDocument 401/error.php?error=401
ErrorDocument 403/error.php?error=403
ErrorDocument 404/error.php?error=404
ErrorDocument 500/error.php?error=500

3) created error.php in my root html folder, including code like:
 if ($error>0) {
  echo "

Code $error ..

";
  .. etc
 }
?>

Roger

Re: custom 404 error page
« Reply #4 on: April 22, 2003, 09:07:06 AM »
oops .. should have a space in there some where ..

ErrorDocument 400 /error.php?error=400
ErrorDocument 401 /error.php?error=401
ErrorDocument 403 /error.php?error=403
ErrorDocument 404 /error.php?error=404
ErrorDocument 500 /error.php?error=500

Paul Wolsink

Re: custom 404 error page
« Reply #5 on: April 23, 2003, 11:48:35 PM »
Hi all
Thanks for the tips. I got it working now at last. I had the
htaccess rpm
installed, but could not get it to work, but eventually last
night and
tweaking this morning it's working.

What I did for anyone who wants to know (as there were gaps
in the advise
which I found here in the forums)

Ran the htaccess rpm as discussed in a previous message in
this thread.
Don't change anything in the apache conf (httpd.conf) (I
tried that as well
, but you shouldn't)
Place an .htaccess file in the root where you need to
capture all lost
files.

ie.
.../ibays/domain/html/.htaccess   will capture all lost
files in sub sequent
directories.
.../ibays/domain/html/photos/.htaccess will only capture
lost files in
/photos/ and subsequent directories.

My .htaccess file lokked like this:
ErrorDocument 404 /err404.html^
Where:
ErrorDocument telling Apache what to do, what to look for.
404 the type of error (You can add more error codes like
Roger said)
/err404.html is a flat HTML file, but could be like the file
Roger mentioned
with PHP code. This file is in the root of this ibay.
(I had my files all over the place and tried all the
combinations- like
primary, etc/httpd, etc)
/ means root of THIS Virtual Domain and NOT primary.

What I had in my err404.html is a short notice which says
page is missing,
please click on link if javascript doesn't take you back and
then the
Javascript or link will take you to the root which is
default.php in my
case.

This works for images as well. If you call a image.jpg
direct in the browser
and the images doesn't exist, then it will show this page.

.htaccess can be made rather complicated with all kinds of
tricks like
preventing deep level linking.

REMEMBER to clear the cache . I battle for hours just
because I didn't clear
the cache of my browser. It might help to clear the squid
proxy cache as
well, I'm not sure.

regards
Paul

Charlie Brady

Re: custom 404 error page
« Reply #6 on: April 24, 2003, 03:04:56 AM »
Paul Wolsink wrote:

> Thanks for the tips. I got it working now at last. I had the
> htaccess rpm
> installed, but could not get it to work, but eventually last
> night and
> tweaking this morning it's working.

You don't need .htaccess to do what you want to do. You could just add the lines you need in a custom template fragment, re-expand the httpd.conf template, and restart apache.

The only time you'd ever want .htaccess support is to delegate some part of apache access management to someone who isn't the admin. The SME server templating system already achieves most of what .htaccess does.

Regards

Charlie

dean

Re: custom 404 error page
« Reply #7 on: June 27, 2003, 02:58:25 AM »
Any chance of supplying the line and commands ?

TIA

Dean

Thad Buzolich

Re: custom 404 error page
« Reply #8 on: November 05, 2003, 07:25:52 PM »
1) Change to custom template directory

> cd /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf

2) Make template

> pico 11ErrorDocs

Contents of 11ErrorDocs:
------------------------------------------
ErrorDocument 500 /error.php
ErrorDocument 404 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 402 /error.php
------------------------------------------

error.php is located in my primary/html folder.  Check permissions and owner.

3) Expand templates

> /sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf

4) Restart apache

> /etc/rc.d/init.d/httpd graceful