Forum Moderators: phranque
I want to redirect all SE users with "bar" and "bar2" search terms to http://bar.com/bar_landing.html
And I want to analyze not only one SE - i.e. referrer's formats may differ.
For ex.:
^http://(www)?\\.?google.*, q= for Google
^http://search\\.yahoo.*, p= for Yahoo
^http://search\\.aol.*, userQuery= for AOL
^http://search\\.lycos.*, query= for Lycos
etc.
Referrer must be untouched, all terms except "bar" and "bar2" must proceed as usual.
Any ideas?
Welcome to WebmasterWorld!
See this recent thread [webmasterworld.com] for a start, then post any questions back here.
Jim
Hmmm...
It's close, but needs a lot ow work on it...
And I want to get a more "readable" solution...
Smth like this (don't bite me for syntax, it's nuts)
======================
$key1 = foo
$key2 = foo2
ConditionWithPattern [googleblabla...]
ConditionWithPattern [googleblabla...]
ConditionWithPattern [AOLblabla...]
ConditionWithPattern [AOLblabla...]
RedirectIfHit * [foo.com...]
=======================
Simple to modify, simple to add/edit SEs, human readable.
Should it work?
This is what I call dumb construcrion :(
Is any type of "variable" in htaccess?
[edited by: jdMorgan at 12:53 am (utc) on Mar. 30, 2007]
[edit reason] Disabled smilies in code [/edit]
google\.[^?]+[\?&].*q=
google\.[^?]+\?([^&]+&)*q=
Other than that, it looks OK -- Test it with a user-agent spoofer (I use the "PrefBar" Firefox extension, which has this facility, as does the "Web Developer" extension), and see if it works.
Derivation, construction, and experimentation are how most folks learn this stuff -- The documentation leaves quite a bit of room for interpretation, and of course, there are an infinite number of regular expressions -- both valid and invalid... :)
[added] You *will* need to add an [OR] flag to all but the final RewriteCond, since you want the rule to execute if any of the referrer-bot RewriteConds are true. [/added]
Jim
[edited by: jdMorgan at 1:07 am (utc) on Mar. 30, 2007]
To clarify the "associativity" aspect, using POSIX 1003.2 atomic back-references, you can do an indirect compare of two variables using the fact that if A+B is equal to A+A, then A and B are equal. But again, this technique is too OS-dependent to be relied upon.
mod_rewrite code and regular expressions are certainly not user-friendly. On the other hand, they can be used to create extremely compact and powerful functions, and are best seen in that light. If you want user-friendliness, then look into using a RewriteMap to invoke a PERL script that accesses a database to retrieve URL translations. If you do that, then the "friendliness" can be embodied in the database GUI, albeit at the cost of a lot of up-front work. You'll also need to have access to the server configuration files to define the RewriteMap; This is not available in .htaccess, although once defined, a map can be used in .htaccess.
Jim