Redirect only if coming from specific page

I need users redirected to a specific page but only if coming from another specific page.  I am running apache, php.  

Thanks!
Large_FarvaAsked:
Who is Participating?
 
asadhaiderConnect With a Mentor Commented:
This should do the trick. Change the values of "mydomain.com" and "folder" only, to what your domain is (leave the www. out).
<?php
$referrer = $_SERVER['HTTP_REFERER'];

if (preg_match("/mydomain.com\/registration\//",$referrer)) {
      header('Location: http://www.mydomain.com/folder/');
}
?>

Open in new window

0
 
leakim971PluritechnicianCommented:
Use document.referrer : http://www.w3schools.com/jsref/prop_doc_referrer.asp


<script>
if( document.referrer.indexOf("google.com") >= 0 ) {
      location.reload = "http://www.experts-exchange.com";
}
</script>

Open in new window

0
 
asadhaiderCommented:
The above code uses javascript, using PHP code would be much better for your site. The following code will work, the referrer variable stores the referring page and the if statements check that referrer and match it against site1.com, site2.com and redirect if matches are made.

If you give the exact referring page which you want redirected and the page the redirect should go to, then I'll modify the code above if you want.
<?php
$referrer = $_SERVER['HTTP_REFERER'];

if (preg_match("/site1.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site2.html');
} else {
      header('Location: http://www.customercare.com/home-page.html');
}
?>

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Large_FarvaAuthor Commented:
Thanks for the help!

@asadhaider:  Here is what I need:
If someone comes from http://www.mydomain.com/registration/ 
then
redirect to http://www.mydomain.com/folder/

Thanks!
0
 
Large_FarvaAuthor Commented:
Not working yet.  I put the above code with my changes above everything in the header file of my cms.  Is that the right location?

0
 
Large_FarvaAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.