I have got two hostnames (e.g. www.site1.com and www.site2.com) planned towards the same apache virtual host. Let me redirect all traffic from site1.com to site2.com, except for those Publish demands from the particular folder. (That folder consists of Web addresses that are utilized by older clients which aren't able to handle redirects on Publish demands.)

Here's the rule I emerged with. I am a newbie to rewrite rules, so desired to make certain I wasn't missing anything apparent.

RewriteCond %{HTTP_HOST} ^www.site1.com$
RewriteCond %{HTTP_METHOD} ^POST
RewriteCond %{REQUEST_URI} !^/dontredirectme/
RewriteRule /(.*) http://www.site2.com/$1 [R=301,L]

Is a proper rule for this task? And when yes, what are the efficiency optimizations I ought to be thinking about?

Your rule set looks relatively correct, but you have to modify your next RewriteCond just a little to mirror your ultimate goal:

RewriteCond %{HTTP_METHOD} !^POST [OR]

This will help you to redirect when the request type is not Publish, or it's and also the asked for URI is not /dontredirectme/, which effectively produces a redirect for exactly what is not a Publish request to /dontredirectme/.

Furthermore, the input towards the RewriteRule won't have a number one forward slash if you are determining it inside a per-directory context (inside a .htaccess file or perhaps in a <Directory> section). If you're determining it directly within the <VirtualHost> (a per-server context), then your input may have a number one slash, so that your rule could be fine as-is.

So far as efficiency goes, rules defined within the server configuration have the advantage of only needing to be parsed once. However, b .htaccess file should be parsed for every request, a procedure that involves the extra (although small) overhead of reading through the file and producing the standard expressions.

If you want to squeeze efficiency from it, you can result in the following changes:

RewriteCond %{HTTP_HOST}    =www.example.com
RewriteCond %{HTTP_METHOD} !=POST [NC,OR]
RewriteCond %{REQUEST_URI} !^/dontredirectme/
RewriteRule ^ http://www.example.net%{REQUEST_URI} [R=301,L]

I doubt the main difference is actually significant in most however the most extreme cases, but this removes two regular expressions towards an immediate text comparison. Also, since you want to redirect the request towards the new host verbatim, you are able to "simplify" the standard expression active in the RewriteRule and merely use %{REQUEST_URI} directly within the alternative.