Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect question

htaccess referer

         

gervais27

11:50 am on Jun 23, 2008 (gmt 0)

10+ Year Member



I have sifted through all the top results in google for a way to redirect a user based on the referer data. I want to refer visitors from 1 site and 1 of its subdomains to an article when they visit the site. From everything I have read I came up with the following:

RewriteEngine On
RewriteCond %{HTTP_referer} ^http://(www\.)?example\.com/ [NC]
RewriteCond %{HTTP_referer} ^http://subdomain\.example\.com/
RewriteRule .* [mysite.com...] [R,L]

I have not been able to test the subdomain rewrite condition but the domain one does the redirect but gives the following error:

The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.

From what I've read it is probably looping? I have SEF urls enabled through joomla, not sure it matters or not. I real have no knowledge of this but have always found solutions with google. Any help would be great and since this is my first post thanks for all the help to even get me to this point, especially jd01, and jdMorgan.

Thanks

jdMorgan

6:58 am on Jun 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you've got a loop. You need to explicitly prevent requests for the example.com/article/ URL from being redirected to itself. You also need an [OR] flag on that first RewriteCond; Otherwise, the referrer would have to be two different hostnames at the same time, which is clearly impossible:

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?referrer\.com [NC[b],OR[/b]]
RewriteCond %{HTTP_REFERER} ^http://subdomain\.referrer\.com
RewriteRule [b]!^article/[/b] http://www.example.com/article/ [R=302,L]

If *all* hostnames at referrer.com should be redirected to /article, then you could replace both RewriteConds with just one:

RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*referrer\.com [NC]

Jim

gervais27

11:15 am on Jun 24, 2008 (gmt 0)

10+ Year Member



Solved- Thanks so much for your response. I took your suggestion and used one line!

Thanks alot!