• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1416
  • Last Modified:

.htaccess - 404 redirection - HTTP_REFERER

My server and web programming expertise is with Windows servers and ASP. My PHP is rudimentary at best, and I'm trying to learn as I go along while solving practical problems.

What I need to do is redirect to a specified page on on a different domain when an invalid URL is entered into the browser.

For example if:
http://www.MyActualDomain.com/BadFolder/index.php
does not exist, then the visitor is redirected to:
http://www.MyOtherDomain.com/404handler.php

As I understand it the conventional way to do that is via a redirect in the .htaccess file.

I have done that and it worked fine.

------------------------------
NOW FOR THE PROBLEM:
------------------------------

Using the above examples, a script in 404handler.php needs to know the bad URL.

Here is a snippet of test code I put together trying to figure out these environment variables:

<?
$host = getenv("REMOTE_HOST");
$referrer = getenv("HTTP_REFERER");
$path = getenv("REQUEST_URI");

echo "REMOTE_HOST  = " . $host . "<br />";
echo "HTTP_REFERER = " . $referrer . "<br />";
echo "REQUEST_URI  = " . $path . "<br />";

?>

REMOTE_HOST returns my own IP as expected, but the other two strings are empty.

I've also tried $_SERVER['REQUEST_URI'] in place of the getenv method.

Anyone got a solution?


-----------------------------------------------------------------------------
Here's PHPinfo on the server where 404handler.php resides:
-----------------------------------------------------------------------------
PHP Version 5.0.5

System       Windows NT NT24 5.2 build 3790
Build Date       Sep 5 2005 15:50:13
Configure Command       cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
Server API       CGI/FastCGI
Virtual Directory Support       enabled
Configuration File (php.ini) Path       C:\WINDOWS\php.ini
PHP API       20031224
PHP Extension       20041030
Zend Extension       220040412
Debug Build       no
Thread Safety       enabled
Zend Memory Manager       enabled
IPv6 Support       enabled
Registered PHP Streams       php, file, http, ftp, compress.zlib
Registered Stream Socket Transports       tcp, udp
-----------------------------------------------------------------------------
0
Soporose
Asked:
Soporose
2 Solutions
 
OscurochuCommented:
try forwarding it to, for example

http://www.MyOtherDomain.com/404handler.php?u=http://www.MyActualDomain.com/BadFolder/index.php

I'm sure there's another way, but that might be the easiest.
0
 
hernst42Commented:
Try the following $_SERVER variables for the missed url:
    'REQUEST_URI',
    'QUERY_STRING',
    'REDIRECT_SCRIPT_URI',
    'REDIRECT_URL',
    'HTTP_REFERER'
0
 
CWS (haripriya)Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
  Delete - no points refunded

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cyberwebservice
Experts Exchange Cleanup Volunteer
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
hernst42Commented:
objection: Split points
0
 
OscurochuCommented:
I agree
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now