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, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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... |
|
|||
|
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 ================================================== ========================= |
|
|||
|
"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? |
|
|||
|
>>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? |
|
|||
|
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 > > |
|
|||
|
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. |
|
|||
|
"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 |
|
|||
|
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 > |
|
|||
|
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. |