Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Custom 404 with Redirection Based on Referrer
Old 09-11-2009, 04:53 PM Custom 404 with Redirection Based on Referrer
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
Will this work? Is there a better way?
It tested ok in IIS, I have yet to try on my apache servers.

Problem:

Needed a custom 404 page with intelligent redirect based upon the referrer. Easy with Apache, not as easy with IIS.

Solution???:

PHP Code:
<?php 
 
// ### Set $eREF to the Referring Page using QUERY_STRING (IIS) or REDIRECT_URL (apache)
 
$eREF = !isset($_SERVER['REDIRECT_URL']) ? !isset($_SERVER['QUERY_STRING']) ? NULL substr($_SERVER['QUERY_STRING'],4) : $_SERVER['REDIRECT_URL'] ;

 
// ### Redirect Based on the Referring Page
 
switch ($eREF) {
   case 
"http://host/badpage1.php":
     
header"HTTP/1.1 301 Moved Permanently" );
     
header("location: http://host/goodpage1.php");
     exit;
   case 
"http://host/badpage2.php":
     
header"HTTP/1.1 301 Moved Permanently" );
     
header("location: http://host/goodpage2.php");
     exit;
 }
?>
I should also be able to do something like:
PHP Code:
<?php
 
// ### Redirect Based on Regexp
 
$pattern '/^([a-zA-Z0-9]*)$/i'
 
if (preg_match_all($pattern$eREF$match) === 0)
   {
     
header"HTTP/1.1 301 Moved Permanently" );
    
header("location: http://host/lookingfornumbers.php");
    exit;
   }
?>

Last edited by Envision_frodo; 09-11-2009 at 04:54 PM.. Reason: Changed CODE to PHP for better highlighting
Envision_frodo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-15-2009, 02:11 AM Re: Custom 404 with Redirection Based on Referrer
Experienced Talker

Posts: 46
Trades: 0
I'm pretty sure you can use mod rewrite in apache to do what you are trying to do in PHP. It would make it much easier.
__________________

Please login or register to view this content. Registration is FREE
-> Home of the crasher squirrel
jeff_oneil is offline
Reply With Quote
View Public Profile Visit jeff_oneil's homepage!
 
Old 09-21-2009, 02:46 PM Re: Custom 404 with Redirection Based on Referrer
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
Trades: 0
Thanks, only problem is I need a cross-platform solution.
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Custom 404 with Redirection Based on Referrer
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41491 seconds with 12 queries