Question

E.g. I have two domains:

http://www.computer.com
http://www.computers.com

http://www.computer.com is main website and http://www.computers.com is just dummy that will redirect to main website (http://www.computer.com).

So my goal with pure PHP is to detect that user comes from http://www.computers.com rather than google or other website or directly typing url without using refer since it can be disabled.

Both sites are on same hosting, but I cannot access file system of one site from another. And $_SESSION is or $_COOKIE are domain specific variables too.

Was it helpful?

Solution 2

Your best bet is to to address your issues on multiple levels. First you should point DNS for www.computers.com to point at the IP address for www.computer.com. Now both of your requests are being served by the same server or cluster of servers(if behind a load balancer).

Second, if you actually want to rewrite the URL to utilize a single domain (to consolidate your cookies, sessions, etc.), then you could use webserver redirection (i.e. mod_rewrite for Apache) to redirect all the requests to the final domain.

Finally, in that rewrite, you should send 301 codes on rewrite to make sure that spiders and such know that this is a permanent redirection.

OTHER TIPS

You could set your redirect script to push to www.computer.com?ref=sister or some similar URL, then log accordingly and, if desired, redirect back to home to keep it transparent to the user.

Are you asking for an htaccess example though? Or just ideas on how to do it?

You say pure php in your computers.com index file:

    <?php 
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: http://www.computer.com?ref=sister"); 
    ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top