Is This Possible? Create URL Identifier Based On HTTP Referrer

by 5 replies
7
I would like to add an identifier to the end of any URL if a visitor comes from any page on the facebook.com domain.

It would need to be appended to the target page dynamically.

If they were going to my index.html page, then i would like the URL to be:

...index.html?ID=FB

...or if they were hitting something in the articles folder then...

.../articles/page.html?ID=FB

Multiple people will be placing the inbound links on facebook and I cannot trust them to add the identifier, so I'd like my server to do it on the fly.

I am trying to track anything coming from facebook (mainly conversions LOL) and eventually would like to do this with all social domains (Twitter, LinkedIn etc...)

Thanks for any input!
Oneal
#programming #based #create #http #identifier #referrer #url
  • Well, you could use .htaccess to check the referrer and rewrite the url or if you are using scripted pages you could add code to check the referrer.
    I'm not an htaccess expert, so I can't give you an example of how to do it, but it can be done.
  • A htaccess rule could look something like this. Haven't tested it

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} ^http://facebook\.com
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule . %{REQUEST_URI}?id=FB [R=301,L]
    • [1] reply
    • I haven't tested it, but would something like this work?

      <?php
      $referer = $_SERVER['HTTP_REFERER'];
      if ($referer == "http://www.facebook.com")
      {header("Location:http://www.yourwebsite.com?ID=FB");}
      ?>
  • You should be aware that you can't trust BROWSERS to add the referrer.
    • [1] reply
    • This should do the trick!

      <?php
      $ref_url = $_SERVER['HTTP_REFERER'];

      if( (preg_match("/facebook.com/", $ref_url, $matches) == 1) ) {

      // You need to add your full URL in here, I am just not allowed to post links yet hehe.
      $link = 'domain.com/?ref=FB';

      }
      else if( (preg_match("/twitter.com/", $ref_url, $matches) == 1) ) {

      $link = 'domain.com/?ref=Twitter';

      }

      header('Location: $link');
      ?>

      Let me know if it works or not.

      Regards,
      Stian

Next Topics on Trending Feed