SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: PHP Redirects

  1. #1
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Redirects

    I have a client who has about 60 domain names all using a 301 redirect (in PHP) to a page on his main website. The client wants the title of the page on his main website to change depending on which url the user is redirected from.

    For example you visit websiteA.com -> which 301 redirects you to -> websiteB.com. websiteB.com knows you came from websiteA and chooses the title accordingly.

    Any ideas? The only thing I can think of is passing a get variable containing the domain of websiteA with the redirect, but this seems messy.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  2. #2
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The get variable would definitely work but http_referer would be more efficient. Here's some more info http://www.electrictoolbox.com/php-h...erer-variable/

  3. #3
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wiggsfly View Post
    The get variable would definitely work but http_referer would be more efficient. Here's some more info http://www.electrictoolbox.com/php-h...erer-variable/
    I'm pretty sure this wouldn't work in my situation.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  4. #4
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, the redirect won't pass as a HTTP referrer. If a link was clicked to arrive at websiteA.com, then (in Firefox at least) will pass that value along after a redirect, but it won't indicate what the redirecting site was.

    optl you might be able to use setcookie to record to original domain. Use the domain argument to allow access to the cookie by websiteB.com
    The cookie will only need to live for a short time, as the redirect will be quick.

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But since it's a cookie, this can't be relied on 100% since some browsers may be configured to block cookies?

    In such a case the GET method is probably the most reliable.
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The get method is definitely more reliable but the goal of this is to improve SEO and thus page rank on websiteB. With the get method each redirection url will be different - wouldn't this be a bad idea for page rank? The cookie method may not be 100% reliable but it is probably close to it.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    WebsiteA.php
    PHP Code:
    # HTTP_HOST = websiteA.tld
    header'http:/websiteB.tld/?ref=' urlencode$_SERVER['HTTP_HOST'] ) ); 
    Would be the only sure fire way. The content will be different, so the page is different. Having the URL change with the content would be the best advise to keep the site from being penalized.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  8. #8
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try setting a cookie on their computer. have some generic page that applies for when cookies are turned off or corrupted cookie. Then maybe sha5 the all the urls that you have going to that one site, and store that in the cookie. Then read the cookie look up the hash and display the page.

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Cookies do not work across domains!
    sigh...
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Cookies do not work across domains!
    sigh...
    http://www.15seconds.com/issue/971108.htm
    sign....

  11. #11
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by baileylo View Post
    You should notice, sharing the cookie across domains is moved into a query string. The cookie itself cannot move across the domain boundaries. It would be a privacy issue if that was the case.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  12. #12
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah,
    AFter i had posted that i realized how stupid the whole thing was. I hadn't really thought anything through. Of course you can't share cookies, that only makes sense. And yeah that was through the query string.

  13. #13
    Keep Moving Forward gold trophysilver trophybronze trophy
    Shaun(OfTheDead)'s Avatar
    Join Date
    Nov 2005
    Location
    Trinidad
    Posts
    3,746
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    How 'bout, make the 404 page of each site be the one that does the redirecting, and have it send a GET variable ?

    Trying to fill the unforgiving minute
    with sixty seconds' worth of distance run.

    Update on Sitepoint's Migration to Discourse

  14. #14
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Cookie is only way to ensure this works with the seo stuff.

    WebsiteA.com
    -> 301 redirect ->

    WebsiteB.com?referrer=websiteA.com
    -> Set cookie for host
    -> 301 redirect ->

    WebsiteB.com
    -> Read cookie for previous host (title)
    -> Delete cookie (if no longer required)

    To get around the issue of cookies not being enabled, why not use this as well

    http://www.sitepoint.com/blogs/2009/...iable-library/

  15. #15
    SitePoint Zealot Dorsey's Avatar
    Join Date
    Feb 2004
    Location
    NJ
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We use the brain-dead solution of adding a GET variable to determine the source. Our redirects (from banner ads) are unique to the individual ad, which is also unique to the source. We set up the redirect with a hard-wired source key to unambiguously determine which ad was clicked. So,

    abc.com/adlink.php?src=google1

    Maps to:

    abc.com/specialproduce.php

    Actually, that's simplistic but gives you the idea.

    For logging purposes, every re-direct resolves to a single page (adlink.php) which time stamps the click, logs the source, and then moves to whichever page is targeted by the ad.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •