473,734 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
19 2685
In comp.lang.php Joshua Beall <jb****@donotsp am.remove.me.he raldic.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...

Jul 17 '05 #2
On Tue, 07 Dec 2004 21:29:00 GMT, "Joshua Beall"
<jb****@donotsp am.remove.me.he raldic.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@databa six 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
=============== =============== =============== =============== ===============
Jul 17 '05 #3
"Daniel Tryba" <sp**@tryba.inv alid> wrote in message
news:41******** *************** @dreader3.news. xs4all.nl...
In comp.lang.php Joshua Beall <jb****@donotsp am.remove.me.he raldic.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?
Jul 17 '05 #4
>>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?
Jul 17 '05 #5
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

Jul 17 '05 #6
Joshua Beall <jb****@donotsp am.remove.me.he raldic.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.

Jul 17 '05 #7
Rob

"Joshua Beall" <jb****@donotsp am.remove.me.he raldic.us> schreef in bericht
news:wgptd.1810 $N%6.99@trnddc0 5...
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
Jul 17 '05 #8
d
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 - "RewriteCon d" and "-f" :)

"Joshua Beall" <jb****@donotsp am.remove.me.he raldic.us> wrote in message
news:wgptd.1810 $N%6.99@trnddc0 5...
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

Jul 17 '05 #9
On Wed, 08 Dec 2004 08:55:22 GMT, "Rob" <reply_@news_gr oup.please> wrote:

"Joshua Beall" <jb****@donotsp am.remove.me.he raldic.us> schreef in bericht
news:wgptd.181 0$N%6.99@trnddc 05...
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",
ErrorDocumen t 404 http://mysite.com/pages/display.php
HTH Rob


To take this a step beyond 404 : If there are specific pages which you know to
no longer exist (as opposed to random 404 errors), it's probably wiser to return
a 301 and direct the user agent to the new page automagically. This will, in
theory, cause proxies and search engines to update their old links to the new
page, as opposed to simply deleting them.

For your example :

[.htaccess]
redirect 301 /pages/contact http://mysite.com/pages/display.php

As others have mentioned, an Apache solution is more appropriate in this case
than something scripted in PHP.

HTH !

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2472
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I need: A system whereby the user only has to register ONCE and he will have automatic entry to ANY page without havinto to RE-LOGIN even if he comes in
7
3684
by: Kersh | last post by:
I'm trying to implement XHTML standards in my ASP.NET web pages but whenever I use web controls I get problems because of the very strict nature of W3C XHTML (transitional version is picky but strict1.1 very severe!) e.g. align="Center" fails validation because of the capital "C" - this makes asp:Calendar control unuseable because it happens to use this tag for each of the cells. Also Javascript tags require a 'type' attribute...etc
2
2583
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the browser cache setting (and OS), the program behaves differently. This is how it should work: 1. The client program opens a webbrowser control, using navigate2 method to post xml data to my aspx pages, eg abc.aspx
15
1943
by: dee | last post by:
Hi, I'm curious why MS decided to have Transfer hide the target page's url invisible? Any guesses ? Thanks. Dee.
3
3314
by: jeff29_b | last post by:
I have customers posting data to an asp page. I would like to respond to their request from an asp.net page without doing a response.redirect from the asp page. Is there some way to do a server.transfer from asp to asp.net or intercept the request for the page in iis and handle it in .net with out our users changing their URLs. The complicated part is that this will only be for certain asp pages so it won't be safe to do this across the...
8
2265
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing happens. dim filt as string ... build filter string... UserControl.ReportFilter = filt
7
1751
by: Alan Silver | last post by:
Hello, I have installed the 2.0 framework, and am looking at converting some of my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm doing this by hand, but am having problems. I have a simple page that I made in the beta2 version of VWD. The code behind looks like... using System;
13
2106
by: Stephen Kay | last post by:
Is there a way to redirect every single page on an existing web site through a php function? In other words, say I have a whole functional HTML web site, never written to use any php. Now I would like to have a php function handle displaying every page, for example, instead of: http://www.mysite.com/mypage.html you would call:
0
1611
by: Jonathan Wood | last post by:
I seem to be having errors creating and accessing an SQL database. Unfortunatley, I am brand new to SQL setup and administration issues so this really is not my area of expertise. I know I had to install some type of IIS component to run databases from Visual Studio 2003. Since then, I've installed Visual Studio 2005. I know VS 2005 has some component so that IIS is not required. Here's the two errors:
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.