Forum Moderators: phranque

Message Too Old, No Replies

Referrer search string redirect

Apache rewrite or redirect for specific search string

         

uncobeth

4:26 am on Dec 18, 2007 (gmt 0)

10+ Year Member



Hi -

I saw that this had been discussed before, but I was looking for an example to use.

I have a site and my name is the same as an "adult" actress and a cricket player. When someone googles the name, a lot of people get to my site.

I'd like to use that search string from the referrer to send just those people to another page that tells them I'm not the actress or the cricket player. :)

How would I craft a rewrite so that it looks for the words "<actress name> adult" in the referrer? I've tried a few times on my own, and my efforts have caused my site not to load.

Thanks in advance!
Beth

[edited by: jdMorgan at 4:27 pm (utc) on Dec. 18, 2007]
[edit reason] Removed specifics per Terms of Service [/edit]

jdMorgan

2:23 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best-effort code as a basis for discussion.

Thanks,
Jim

wilderness

2:26 pm on Dec 18, 2007 (gmt 0)

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



Beth,
Perhaps another will come along and provide a redirect.

The best solution would be to modify your page and/or page title with a difference that would separate your website from these other websites?
Even with the SERP of "Beth's", your page still returns in the 9th result.

However, many webmasters would pay dearly to have endless traffic directed to their sites offering potential traffic otherwise not possible.

It's the custom of this forum for the inquiry to provide a "best effort" for others to assist (see forum charter).

Since I'm NOT however providing what you asked for, rather a denial (as opposed to a redirect), I've abused a
loop-hole ;)

the following simply denies access based on the word being contained anywhere in the UA.

RewriteCond %{HTTP_USER_AGENT} porn
RewriteRule .* - [F]

uncobeth

3:57 pm on Dec 18, 2007 (gmt 0)

10+ Year Member



Each time I had a best effort, I wound up deleting it in a big hurry to have my site working once again. I'll give it another try and then report back.

Perhaps you're right though that I shouldn't whine about the traffic to my site!

uncobeth

4:25 pm on Dec 18, 2007 (gmt 0)

10+ Year Member



Here's my complete .htaccess file. I no longer get any errors! But the rules don't work. I'm curious about how to get this working now, because I noticed in my stats that people consistently search on specific phrases relating to myeloma, and I could actually redirect them right to the answers for those questions so they wouldn't have to search through almost 5 years of blog posts.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

RewriteCond %{HTTP_REFERRER} beth+morgan+porn [NC,OR]
RewriteCond %{HTTP_REFERRER} beth+morgan+cricket [NC]
RewriteRule .* - [F]

jdMorgan

4:26 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I seriously doubt that's the kind of traffic you want, given the subject of your site.

The solution you're asking about is relatively simple -- But it will save us a lot of time if we have an example upon which to base discussion, as the example will illustrate where we need to focus effort toward corrections and explanations.

Wilderness brings up a good point: There are several search terms you'll probably want to redirect, not just the main one that identifies the traffic sector.

Thanks,
Jim

jdMorgan

4:45 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We want to look for "beth" in any upper/lowercase variants -- possibly delimited at the beginning or end by the "+" signs used to replace spaces in search engine referrers, or by "?" or "&" as appear in query strings, combined with a list of other objectionable or unwanted terms. Then we want to redirect search referrals to an alternate page, but not if the request is for that alternate page (as it will be after the redirect is invoked), and not if the URL contains a period in the final path-path (as it would for image, script, or CSS file requests. So something like this should work:

RewriteCond %{HTTP_REFERER} [?+&]?beth[?+&]? [NC]
RewriteCond %{HTTP_REFERER} [?+&]?(cricket¦adult¦porno?)[?+&]? [NC]
RewriteCond %{REQUEST_URI} !^alternate_page\.html$
RewriteCond %{REQUEST_URI} !^([^/]+/)*[^/.]+\.[^/.]+$
RewriteRule .* http://www.example.com/alternate_page.html [R=302,L]

You might also want to include variations on the cricket player's past and present team names.

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

[edit]Corrected as noted below. [/edit]

[edited by: jdMorgan at 10:49 pm (utc) on Dec. 18, 2007]

jdMorgan

5:26 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note also that this new code needs to go in front of your WordPress code. Otherwise, it will likely never be invoked.

Jim

uncobeth

9:11 pm on Dec 18, 2007 (gmt 0)

10+ Year Member



Hi Jim,

I thought the Wordpress might be causing something and moved it as you suggested. Ok, here's what I have now (below). I put in some really obvious stuff to test with and then went to google to search on "beth myeloma blog velcade." I see some posts from my blog there and click, but am not sent to cnn.com (just there to test with so it's something obviously different).

I did change the pipe symbols too.

RewriteCond %{HTTP_REFERRER} [?+&]?beth[?+&]? [NC]
RewriteCond %{HTTP_REFERRER} [?+&]?(myeloma¦velcade¦blog?)[?+&]? [NC]
RewriteCond %{REQUEST_URI}!^alternate_page\.html$
RewriteCond %{REQUEST_URI}!^([^/]+/)*[^/.]+\.[^/.]+$
RewriteRule .* [cnn.com...] [R=302,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

jdMorgan

10:18 pm on Dec 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't believe it -- I spelled "REFERRER" correctly. But Apache requires it to be mispelled (it's a long story).

Change the two RewriteCond to look at %{HTTP_REFERER} instead. (corrected above)

Jim

[edited by: jdMorgan at 10:50 pm (utc) on Dec. 18, 2007]

uncobeth

10:31 pm on Dec 18, 2007 (gmt 0)

10+ Year Member



Bingo! Thanks, Jim! I need to look up that story one day.