Forum Moderators: phranque
What I would like to do is to redirect anyone who has an ebay referrer to a page where I explain how to tell if the product is real or a knock off, etc.
So, I need a redirect that will redirect anyone referred by any page on Ebay [cgi.ebay.com...] to one specific page, regardless of the page on my site they are linking to. Make sense?
Here's what I have so far, based on changing code I found for an image redirect. I'm sure the code is brutal, so can anyone help make code that would, you know, work?
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(cgi\.)?ebay\.com/ [nc]
RewriteRule .*\.(htm¦html¦)$ [mysite.com...] [nc]
[edited by: jdMorgan at 7:22 pm (utc) on Dec. 21, 2005]
[edit reason] Fixed smiley in code. [/edit]
If not, then try adding:
Options +FollowSymLinks
If you already have other working RewriteRules, then I'd suggest you look at your raw server error log -- It will often tell you exactly what the problem is, including the problem fix above.
Jim
Looked in my logs, it says:
"mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary."
Not sure exactly what that means.
Is it possible to automatically redirect anyone viewing one of my sites' cached or e-mailed pages on Google's or Yahoo's servers, for example, to its original page? (The preceding eBay example redirects all requests to one page.)
I'm interested in redirecting people (& bots & crawlers) accessing my HTML content on other servers because the images on each page are hotlinked-blocked and I'm ending up with a gazillion 403s in my logs every time someone looks at a page that's somewhere else (including in their local cache). I'm even more keenly interested because my 'seen elsewhere' content has been used in ways my local mod_rewrites prevent.
Alas, I'm unable to test what I'm trying to do on a live site with real off-site referrers. So before I run the risk of
loops within my 90k .htaccess file and/or treating visitors to Server Errors galore, here are three sets of examples, LONG, MEDIUM and SHORT.
What do you think, please?
1.) LONG: Does the following set look somewhat passable?
RewriteEngine on
RewriteCond %{HTTP_REFERER} google\.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} 64\.233\.161\.104/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} 66\.249\.93\.104/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} search\?q=cache [NC,OR]
## Yahoo
RewriteCond %{HTTP_REFERER} yahoo\.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} 66\.94\.231\.568/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ShowLetter\?$ [NC,OR]
## Other
RewriteCond %{HTTP_REFERER} netscape\.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} earthlink\.*$ [NC,OR]
## Local
RewriteCond %{HTTP_REFERER} [127\.0\.0\.1...] [NC]
RewriteRule ^.*$ http://www.example.com/$1 [NC,L]
(The referring URLs have LOADS of variables after question marks but the suffixes seem more consistent than not but for countries: google.ca, google.de, etc. Alas, the prefixes, particularly yahoo's, are more complicated.)
2.) MEDIUM: Alternatively, this next set is simpler and isn't mired in umpteen IP and HOST possibilities --
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(cache¦Inbox¦mail¦Show¦ShowLetter¦user¦webmail)$ [NC,OR]
RewriteCond %{HTTP_REFERER} [127\.0\.0\.1...] [NC]
RewriteRule ^.*$ http://www.example.com/$1 [NC,L]
3. SHORT: Finally, down to basics, and minus the 127.0.0.1 idea. Too succinct or simply doable? Used all on one line:
RewriteEngine on
RewriteRule \(cache¦Inbox¦mail¦Show¦ShowLetter¦user¦webmail)$ http://www.example.com/$1 [NC,L]
Thanks in advance for your help!
2) The first two variations and a correction of the third will require the expresson on the left side of the rewriterule to be parenthesized to create the $1 back-reference.
3) Dump trailing ".*$" sequences. They do nothing but slow down your server, and offer no advantage over a non-end-anchored pattern unless a back-reference is being created. In most cases, this is a dead give-away for auto-generated code.
Because this is an 'optional' rather than 'critical' application, I'd lean more toward something compact like version two:
RewriteEngine on
RewriteCond %{HTTP_REFERER} [?&](cache¦Inbox¦mail¦Show¦ShowLetter¦user¦webmail)= [NC,OR]
RewriteCond %{HTTP_REFERER} http://127\.0\.0\.1/ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Jim
What you'll need is a client-side solution, such as a short JavaScript meta-refresh based on the current page location.
Jim