Forum Moderators: phranque
Senario:
Someone is on www.xyz.com looking at some page, and they click on a link URL=http://www.mysite.com I want that person to be redirected to www.mysite.com/dt/index.html I only have control over mysite.com, not xyz.com
Code in .htaccess file:
RewriteEngine on
RewriteCond {%HTTP_REFERER} ^(www\.)?xyz.com$
RewriteRule ^(.*)$ http://example.com/dt/$1 [R,L]
This code has been through several changes, but this is the latest incarnation, and it's still not working. Links from xyz.com still go to mysite.com/index.html If this can be accomplished another way, I'm perfectly ok with it. I'm not stuck on .htaccess for any reason other than I was told it was the only way. My hosting provider is 1and1, and they told me .htaccess use is permitted. Thank you so much for any help you can offer.
[edited by: jdMorgan at 5:24 am (utc) on June 8, 2007]
[edit reason] example.com [/edit]
But it won't be; It will have "http://" at the beginning, and in most cases, at least a slash at the end.
I'd recommend changing your RewriteCond to:
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?xyz\.com
This condition will now match if the referrer is from any page on www.xyz.com or xyz.com, whether it's a secure (https) or insecure (http) page.
Jim
Current code looks like:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?xyz\.com
RewriteRule ^(.*)$ http://example.com/dt/$1 [R,L]
Any ideas? Thanks again!
[edited by: Raid at 6:20 am (utc) on June 8, 2007]
Yes, it makes a difference -- The code has to match all the observed referrer variants.
So try:
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*xyz\.com
The pattern reads, "match http or https, followed by a colon and two slashes, followed by any number (including zero) of the sequence: (one or more characters not a period, followed by a period) followed by xyz.com, followed by anything or nothing."
Remember to completely flush your browser cache after any change to the code, or after successfully loading any of the normal pages -- If the normal page is in your browser cache, then your browser will not send a request to the server, it will serve its cached copy. If a request isn't sent to your server, then code on your server cannot affect anything, regardless of the referrer.
Jim
There seems to be a quirk in the RewriteRule however. Links are being redirected successfuly, but they are landing on http://example.com/dt/dt/dt/dt/dt/dt... Firefox is reporting an error msg: "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."
Current code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*xyz\.com
RewriteRule ^(.*)$ http://example.com/dt/$1 [R,L]
I have tried a few modifications with no success. Can you see anything in my code that would cause this?
RewriteEngine on
RewriteCond $1 !^dt/
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*xyz\.com
RewriteRule (.*) http://example.com/dt/$1 [R=302,L]
Your explanation helped me a great deal with the HTTP_REFERER line. Just to make sure I understand the last change: RewriteCond $1!^dt/ is basically saying, "if you're not being refered from the dt/ directory ...then continue to the next line of code" Is that accurate?
Thanks once again. I think I may have found a new home on these forums.