Forum Moderators: phranque

Message Too Old, No Replies

Redirecting to a specific page according to referrer

trying to send visitors from certain domains to a specific page on site

         

theney

10:49 am on Nov 24, 2007 (gmt 0)

10+ Year Member



Hi everyone,

I'm having a problem with a rewrite I want to do. Basically, I want to redirect traffic from a certain site to a specific page on my site. I don't see how this would be any different than redirecting to a customized homepage according to the user agent (except for using a different type of RewriteCond), but it doesn't work.

This is the code:

RewriteEngine on
#Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_REFERER} ^http://www.originating-site\.com [NC]
RewriteRule ^.*$ /target-page-on-my-site.html [R]

phranque

11:49 am on Nov 24, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], theney!

what happens when it "doesn't work"?
what response do you get in the browser?
what do you see in the error log?

i notice you didn't escape the first "." in the RewriteCond but that shouldn't cause much problem in this case...

theney

2:54 pm on Nov 24, 2007 (gmt 0)

10+ Year Member



thanks for the welcome.

The link from the referring site points to the homepage so I get sent to the homepage instead to the inner page i want to send the visitors to...

jdMorgan

4:05 pm on Nov 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We will need specific and detailed answers to the three questions posted above in order to be of any assistance here.

Jim

theney

7:51 pm on Nov 24, 2007 (gmt 0)

10+ Year Member



what happens when it "doesn't work"?

It doesn't get redirected to the inner page i wanted. Instead of going to www.mydomain.com/target-page-on-my-site.html, it goes to www.mydomain.com. This is where the link is pointing to on the referring site, I just want to send the visitors coming through that link to a different page.

what response do you get in the browser?

As I described above, I don't get an error code, not a 404 nor a 500. I get the homepage...

what do you see in the error log?

I don't have an error log, but my access log shows this:

[My IP] - - [24/Nov/2007:05:03:16 -0500] "GET /target-page-on-my-site.html HTTP/1.1" 302 223 "http://www.linking-domain.com/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9" 10330

jdMorgan

9:09 pm on Nov 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What happens if you use the 'full' form of the redirect?

RewriteCond %{HTTP_REFERER} ^http://www\.originating-site\.com [NC]
RewriteCond %{REQUEST_URI} !^/target-page-on-my-site\.html
RewriteRule .* http://www.example.com/target-page-on-my-site.html [R=301,L]

Jim

jimbeetle

9:53 pm on Nov 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[My IP] - - [24/Nov/2007:05:03:16 -0500] "GET /target-page-on-my-site.html HTTP/1.1" 302 223 "http://www.linking-domain.com/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9" 10330

I know only enough about rewriting to get myself into hot water, but that 302 response stands out. Is it possible that there's a forgotten redirect from "target=page" lying around somewhere. Since your using Firefox you might want to download the Live HTTP Header plug-in to see all hops from the originating link.

theney

12:51 pm on Nov 25, 2007 (gmt 0)

10+ Year Member



What happens if you use the 'full' form of the redirect?

RewriteCond %{HTTP_REFERER} ^http://www\.originating-site\.com [NC]
RewriteCond %{REQUEST_URI}!^/target-page-on-my-site\.html
RewriteRule .* http://www.example.com/target-page-on-my-site.html [R=301,L]

Jim

Hi Jim,

This seems to have done the trick.

Thank you very much!

So the problem was not using the full URL in the RewriteRule or not using the RewriteCond of %{REQUEST_URI}?