Setting up a page that will intercept all pages that do not already exist?

This is a discussion on Setting up a page that will intercept all pages that do not already exist? within the PHP Language forums, part of the PHP Programming Forums category; Hi All, I would like to setup my site so that when a page is request that does not exist, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-07-2004
Joshua Beall
 
Posts: n/a
Default Setting up a page that will intercept all pages that do not already exist?

Hi All,

I would like to setup my site so that when a page is request that does not
exist, transfer is instead passed to a certain page that I specify. For
instance, if the user requests http://mysite.com/pages/contact and that is
not a valid page or directory, then the request is handed to
http://mysite.com/pages/display.php or something like that.

I am wondering what the best way to do this is - I know that I could use an
..htaccess file to redirect 404 errors, but I would rather not give a 404
error in the first place. Is there a better/other way? I seem to remember
having read about another way... but I can't seem to remember...

This is in a LAMP environment, and does not need to be portable to Windows
or any other webserver.

Any help would be greatly appreciated!

His,
-Josh


Reply With Quote
  #2 (permalink)  
Old 12-07-2004
Daniel Tryba
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

In comp.lang.php Joshua Beall <jbeall@donotspam.remove.me.heraldic.us> wrote:
> I am wondering what the best way to do this is - I know that I could use an
> .htaccess file to redirect 404 errors, but I would rather not give a 404
> error in the first place.


It's called a 404 handler, but it doens't have to return an http error
status. In the 404 handler script you can either return a 404 (the
default status) or choose to do anything else you might come up with,
like redirecting to the correct url in case of small typos. The client
will never find out it was handled by the 404 handler...

Reply With Quote
  #3 (permalink)  
Old 12-07-2004
Gary L. Burnore
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

On Tue, 07 Dec 2004 21:29:00 GMT, "Joshua Beall"
<jbeall@donotspam.remove.me.heraldic.us> wrote:

>Hi All,
>
>I would like to setup my site so that when a page is request that does not
>exist, transfer is instead passed to a certain page that I specify. For
>instance, if the user requests http://mysite.com/pages/contact and that is
>not a valid page or directory, then the request is handed to
>http://mysite.com/pages/display.php or something like that.
>
>I am wondering what the best way to do this is - I know that I could use an
>.htaccess file to redirect 404 errors, but I would rather not give a 404
>error in the first place. Is there a better/other way? I seem to remember
>having read about another way... but I can't seem to remember...
>
>This is in a LAMP environment, and does not need to be portable to Windows
>or any other webserver.
>
>Any help would be greatly appreciated!



This is really more of a webserver question and it really depends on
the webserver you're using. You mention .htaccess, so I'll assume
apache.

edit the httpd.conf file (/etc/httpd/conf/httpd.conf

and look for this:

#ErrorDocument 404 /missing.html


Uncomment it and change the url to what you want.

restart the server
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Reply With Quote
  #4 (permalink)  
Old 12-08-2004
Joshua Beall
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

"Daniel Tryba" <spam@tryba.invalid> wrote in message
news:41b622af$0$33205$e4fe514c@dreader3.news.xs4al l.nl...
> In comp.lang.php Joshua Beall <jbeall@donotspam.remove.me.heraldic.us>
> wrote:
>> I am wondering what the best way to do this is - I know that I could use
>> an
>> .htaccess file to redirect 404 errors, but I would rather not give a 404
>> error in the first place.

>
> It's called a 404 handler, but it doens't have to return an http error
> status. In the 404 handler script you can either return a 404 (the
> default status) or choose to do anything else you might come up with,
> like redirecting to the correct url in case of small typos. The client
> will never find out it was handled by the 404 handler...


Ah ok.

Are there other ways to do it? What are they? Do they provide advantages
of some sort? Is there any reason to not go the 404 handler route?


Reply With Quote
  #5 (permalink)  
Old 12-08-2004
Joshua Beall
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

>>This is in a LAMP environment, and does not need to be portable to Windows
>>or any other webserver.

>
> This is really more of a webserver question and it really depends on
> the webserver you're using. You mention .htaccess, so I'll assume
> apache.


The 'A' in LAMP stands for Apache.

Are their other ways to do this sort of thing, and if so, do they provides
advantages over the 404 handler method?


Reply With Quote
  #6 (permalink)  
Old 12-08-2004
paul
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not alreadyexist?

You could place redirect index.php scripts using the header() function
in each of those mystery folders if they are specific known ones,
otherwise the .htaccess solution doesn't appear to be an error to the
user, it just proceeds to the page you specify instead of showing the
error message. The faulty url actually remains in the address bar, at
least with mozilla.

Joshua Beall wrote:
> Hi All,
>
> I would like to setup my site so that when a page is request that does not
> exist, transfer is instead passed to a certain page that I specify. For
> instance, if the user requests http://mysite.com/pages/contact and that is
> not a valid page or directory, then the request is handed to
> http://mysite.com/pages/display.php or something like that.
>
> I am wondering what the best way to do this is - I know that I could use an
> .htaccess file to redirect 404 errors, but I would rather not give a 404
> error in the first place. Is there a better/other way? I seem to remember
> having read about another way... but I can't seem to remember...
>
> This is in a LAMP environment, and does not need to be portable to Windows
> or any other webserver.
>
> Any help would be greatly appreciated!
>
> His,
> -Josh
>
>

Reply With Quote
  #7 (permalink)  
Old 12-08-2004
Daniel Tryba
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

Joshua Beall <jbeall@donotspam.remove.me.heraldic.us> wrote:
[404 handler]
> Ah ok.
>
> Are there other ways to do it? What are they? Do they provide advantages
> of some sort?


You could use the rewriteengine to redirect all requests to 1 script.
http://httpd.apache.org/docs/misc/rewriteguide.html

> Is there any reason to not go the 404 handler route?


Can't think of any.

Reply With Quote
  #8 (permalink)  
Old 12-08-2004
Rob
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?


"Joshua Beall" <jbeall@donotspam.remove.me.heraldic.us> schreef in bericht
news:wgptd.1810$N%6.99@trnddc05...
> Hi All,
>
> I would like to setup my site so that when a page is request that does not
> exist, transfer is instead passed to a certain page that I specify. For
> instance, if the user requests http://mysite.com/pages/contact and that is
> not a valid page or directory, then the request is handed to
> http://mysite.com/pages/display.php or something like that.
>
> I am wondering what the best way to do this is - I know that I could use
> an .htaccess file to redirect 404 errors, but I would rather not give a
> 404 error in the first place. Is there a better/other way? I seem to
> remember having read about another way... but I can't seem to remember...
>
> This is in a LAMP environment, and does not need to be portable to Windows
> or any other webserver.
>
> Any help would be greatly appreciated!
>
> His,
> -Josh
>


When using a .htaccess file you only catch the 404 error and you don't need
to "give the 404 error"(?). As a response you can redirect to any page
without letting the user know it was a 404 error. i.e.:

[.htaccess]
# "404 Not Found",
ErrorDocument 404 http://mysite.com/pages/display.php


HTH Rob


Reply With Quote
  #9 (permalink)  
Old 12-08-2004
d
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

hi!

mod_rewrite in Apache supports what you want to do. I'm not going to tell
you exactly how to do it - you should read the docs yourself if you want to
go this route.

http://httpd.apache.org/docs/mod/mod_rewrite.html

d.

ok, two hints - "RewriteCond" and "-f" :)

"Joshua Beall" <jbeall@donotspam.remove.me.heraldic.us> wrote in message
news:wgptd.1810$N%6.99@trnddc05...
> Hi All,
>
> I would like to setup my site so that when a page is request that does not
> exist, transfer is instead passed to a certain page that I specify. For
> instance, if the user requests http://mysite.com/pages/contact and that is
> not a valid page or directory, then the request is handed to
> http://mysite.com/pages/display.php or something like that.
>
> I am wondering what the best way to do this is - I know that I could use
> an .htaccess file to redirect 404 errors, but I would rather not give a
> 404 error in the first place. Is there a better/other way? I seem to
> remember having read about another way... but I can't seem to remember...
>
> This is in a LAMP environment, and does not need to be portable to Windows
> or any other webserver.
>
> Any help would be greatly appreciated!
>
> His,
> -Josh
>



Reply With Quote
  #10 (permalink)  
Old 12-08-2004
Andrew
 
Posts: n/a
Default Re: Setting up a page that will intercept all pages that do not already exist?

Using the ErrorDocument 404 syntax to redirect everything not found to
a PHP script will issue a 404 header to the browser, but none of the
browsers I have tried, Opera, Firefox or IE show an error page provided
the header is followed by html.

If it works don't knock it, and you can always combine the method with
some static html caching.

The only other alternative I can think of is to use mod_rewrite in
apache somehow.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0