Looking to redirect from referrer to a different page on my website. For example: I have links posted on digg.com going to http://mywebsite.com I would like to have these visitors go to http://mywebsite.com/newpage.html I've searched google on this, .htaccess, javascript, and php, but all the code's in forums I found don't work for me as I believe they are doing more complex redirects then what I'm trying to do. Anyone know the proper way to do a PHP redirect based on referrer?
Can simple if (strpos($_SERVER['HTTP_REFERER'], 'digg.com')) header('Location: http://mywebsite.com/newpage.html'); PHP: do the job?
Yes that did work, but now I get this error when trying to view my domain from other referrer or by just type in. and is this the proper code
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed) Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] Please REPLACE domain.com and www.newdomain.com with your actual domain name. Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled. or PHP Redirect <? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); ?> Point change http://mywebsite.com/ to http://www. mywebsite.com/ in htaccess as well as SE will see this as different domains The first example will work but ensure you have mod_rewrite enable on your server
You should check your other code (or paste it in here), as the that line cannot through you into redirect loop unless you include it in newpage.html and your HTTP_REFERER string has 'digg.com' in it.
So your page contains only this one line of code? To debug you can replace it with: <?php if (strpos($_SERVER['HTTP_REFERER'], 'digg.com')) echo "will redirect"; ?> PHP: and see what happens when you access it using different referers or no referer.
For Wordpress Users WPTrafficTools is an inexpensive alternative to manually coding the php detection profiles in.Â
@ravenplus, I recommend to write exit(); after header statement. let me know if you have still redirect problem