Franki wrote on Sun, Nov 10, 2002 at 08:30:30PM +0800 :
> 
> <IfModule mod_rewrite.c>
>   RedirectMatch ^.*\.(exe|dll|ida|idq).* http://www.microsoft.com/root.exe
> <IfModule>
> I put root.exe on the end of the url, because I want it to show up on their
> logs as something other then a page hit, and $1 was just adding exe to the
> end..
> ie it was redirecting to www.microsoft.comexe
> any ideas on how to pass the exact string that was requested onto the end of
> the M$ url???

What's getting you is called "regular expressions" aka regexp aka regex.
The value of $1 is whatever matches what is in the ().  You are
literally telling it to set $1 to exe or dll or ida or idq.  Try this:

RedirectMatch ^http://[^/]+(.*\.{exe|dll|ida|idq}.*)$ http://www.microsoft.com/root.exe

The first ^ means beginning of line (or beginning of string in this
case).

The "http://"; literally matches the string "http://";.

The [^/]+ means 1 or more characters that are not a /.  This should
match the hostname portion (which we don't care about).

The next part is where the magic happens.  Everything that matches
inside parenthesis will be assigned to $1.  Let me go through the bits
one by one:

.*                   Match everything.  By definition, it will match
                     as much as it can and stop when the following rules
                     match.  Assuming "greedy" mode.  If you have to
                     ask, go buy the "Mastering Regular Expressions"
                     book by O'Reilly.

\.                   Match a literal ".".  Have to escape it because
                     the . is also a wildcard that matches any char.
{exe|dll|ida|idq}    Match any of those 4 letter sequences.  This and
                     the previous rule match any ".exe" or ".dll" (etc)
                     sequence within the URL.  The initial ".*" matches
                     all characters before that starting with the first
                     "/" character (since the http://[^/]+ matched
                     everything up to but not including the leading /).
.*                   Anything else is matched, such as ?user=500.
$                    End of line (or end of string in this case).

Let me know how this works.  It is completely untested and it may just
break your apache logging.  Test it first.

Blue skies...                   Todd
-- 
Never take no as an answer from someone who's not authorized to say yes.
                                                --Ben Reser on Cooker ML
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.19-18mdkenterprise

Attachment: msg60832/pgp00000.pgp
Description: PGP signature

Reply via email to