i want to know how do we find if any page doesnot exist on my server and then redirect it to some other page

i mean if i get 404 page not fount then i want that some other page should be displayed

please help

    There are two ways, one is a bit of a hack and the other one is a bit more complicated.

    The first one is to actually make the 404 page a script that does a lookup or whatever you want. If the lookup (on filesystem or in a database for example) fails, then it displays the 404 error page. This is not good because you get all your hits in the error log :-) But I know that even big companies, like Vignette uses this method on their StoryServer and other products.

    The second one is the true one. If you run Apache you can use a module called mod_rewrite which rewrites urls. This module is very very very complicated, and at the same time veryveryvery powerful. If you're using IIS then you can find or write your own ISAPI filter. I know the ASP monkeys at our company use a such thing. I dont know what it does but it grabs urls and points them to one file (said in a simple manner).
    The functionality is basically the same as the first one.

    So, either, hack the 404 page, or find a guru that knows regular expressions and such and code your own mod_rewrite RewriteRules to satisfy what you're trying to achieve.

    Good luck!

    /Jocke

    PS, my the above email might be f**ked due to some of my ISPs DNS problems, but you can reach me at pjs@aspectgrop.co.uk too...

      Apache directly supports specifying a custom error page. Quoting from httpd.conf on one of my projects:

        ErrorDocument 404 /404.php

      If this is what you're referring to as method 1, I sure wouldn't call it a hack since it's such a straightforward feature supported by the system.

        Well, it's a hack because the custom error page is supposed to be an error page (not a gateway to the web application), as I said, it also logs all "hits" to the error log.

        A pro would not like that (or a paying customer for that matter).

        But, I agree, it's very easy. I personally use mod_rewrite with a few rewrite rules.

        ./jocke

          Where abouts in the Apache httpd.conf do i put this??? mine says:

          2) local redirects

          #ErrorDocument 404 /missing.html

          to redirect to local URL /missing.html

          #ErrorDocument 404 /cgi-bin/missing_handler.pl

          N.B.: You can redirect to a script or a document using server-side-includes.

          Do i change it to this:

          2) local redirects

          ErrorDocument 404 /404.html

          to redirect to local URL /missing.html

          #ErrorDocument 404 /cgi-bin/missing_handler.pl

          N.B.: You can redirect to a script or a document using server-side-includes.

          #

          Thanks,
          Max Slade

            If you have a virtual host, then it needs to go in between the <VirutalHost> directives, otherwise, it goes outside of it, and yes, that is the correct way. "Just" remove the #'s and change the path according to your file/path.

            I still recommend using mod_rewrite (had to say that).

            /Jocke

              This is the mod_rewrite code I use, it's not perfect, but it seems to work.

              Rewrite all '404s' to the script

              RewriteEngine On
              #RewriteLog /tmp/rewrite.log
              RewriteCond /home/user/public_html/%{REQUEST_FILENAME} !-F
              RewriteRule (.+) /thisfilereceivesallrequest.php [NS]

              Now, I can't give much support on that, coz I don't know exactly what it does. It took me two days to fix it... so, use it with caution on on your own risk :-D

              /Jocke

              PS, this is the "right way" and no hack ;-)

                4 months later

                First if the intention is to provide the user with a more sensible errorpage than the standard 404 page, then use Errordocument. This is not a 'hack' but what is was made for.

                Secondly when using mod_rewrite, you should be aware of the amount of memory it uses. I have seen the httpd-process take up another 8M or 16M (dependant on the compiler) memory on a unix-environment when Apache was compiled with mod_rewrite.

                /Dave

                  Write a Reply...