SunQuest
           Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 4th, 2001, 12:27 PM
webguide webguide is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Genoa, Italy
Posts: 3 webguide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb How to get the requested page when the requested page is a 'page not found' (404)?

Hello everybody,
I know I can personalize the 404 error page with my own's errors page or with a message, inserting the following line in the .htaccess file in the website-root directory:
ErrorDocument 404 http://www.myownsite.tld/errors.php

Well, but how can I do to pass the REQUEST_URI to such an URL, i.e. what am I to write in the .htaccess page in order to redirect user to a page that contains the REQUEST_URI in its URL (as a variable), e.g.: http://www.myownsite.tld/errors.php?request={REQUEST_URI}

Since I wrote a statistics service in php, I need to pass it the REQUEST_URI.
Thanks in advance to those who will answer me!
Aldo Medri
URL

Last edited by webguide : April 5th, 2001 at 11:22 AM.

Reply With Quote
  #2  
Old April 6th, 2001, 06:44 AM
dihjital dihjital is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 31 dihjital User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
i guess it should be in HTTP_REFERER so just do a
getenv ("HTTP_REFERER")

Reply With Quote
  #3  
Old April 6th, 2001, 11:49 AM
webguide webguide is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Genoa, Italy
Posts: 3 webguide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Arrow I meant a different thing

Sorry, I meant a different thing, so I'll try to explain better.
If a visitor tries to go to www.myownsite.tld/dfhytjhdjhtfhjfjhfdhjhj , since this URL (this internal path) does not exist, thanks to the .htaccess file, the visitor does not view the browser's 404 error page, but he is redirected to the page I desire, and this page could be, e.g., /404.php.
The referrer is another thing: it's the page the visitor comes from.
But if one tries to go to a page which does not exist, and if the server redirects the user to another page, what I want to catch is WHAT PAGE did the user searche for? And NOT what page he comes from.
So I want that php could know what the user wrote (the REQUEST_URI) to get the /404.php page, and not what page he came from.
Thanks for the suggestion, but I meant a different thing... I hope you can help me...

Reply With Quote
  #4  
Old April 9th, 2001, 04:39 AM
dihjital dihjital is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 31 dihjital User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
what you can do : put an <i> echo phpinfo () </i> into 404.php.
it lists all the environment variables that are available to your script. look for the one which contains the originally requested page.

Reply With Quote
  #5  
Old April 9th, 2001, 11:06 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just use the lesser-known env var -> REDIRECT_URL.

Example of 404.html

<html>
<body>
<h1>File Not Found</h1>
<h2><!--#echo var="REDIRECT_URL"--></h2>
<h3><a href="<!--#echo var="HTTP_REFERER"-->">Please go back</a></h3>
</body>
</html>

Reply With Quote
  #6  
Old April 10th, 2001, 07:42 PM
webguide webguide is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Genoa, Italy
Posts: 3 webguide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry

Thank you, freebsd, but unfortunately it does not work.
Are you sure you can do it with a file with extensio .html, or I need another extension (I tries with .shtml, but it does not work the same.
I think you used a server-side language.
I tried to use $REQUEST_URI in php but it does not works (it gives me the URL about the 404.php page, not the one about the file reqested by the user.
How can I do?

Reply With Quote
  #7  
Old April 11th, 2001, 12:28 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My 404.html was just an example for using something like this:

ErrorDocument 404 /error/404.html

I don't code PHP, if you want a PHP script to handle errordoc, just do:

ErrorDocument 404 /error.php

Within your error.php, the env variable REDIRECT_URL is what you are looking for.

My 404.html also included the env var HTTP_REFERER just so you can compare it with REDIRECT_URL.

>> I tried to use $REQUEST_URI in php but it does not works

It should be $REDIRECT_URL, not $REQUEST_URI.
Say bob is coming from http://www.somewhere.com/links.html and clicked on a link to your site at http://www.yourdomain.com/no_such_file.html, $HTTP_REFERER gives you http://www.somewhere.com/links.html while $REDIRECT_URL gives you /no_such_file.html
Just so you can inform http://www.somewhere.com to update their links.html in regard to your correct html page.

Last edited by freebsd : April 11th, 2001 at 12:41 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > managing REQUEST_URI in case of 404 errors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway