RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} ^Blacklisted-agent1$
RewriteRule ^source1.html$ /dest1.html [R=307]

RewriteCond %{HTTP_USER_AGENT} ^Blacklisted-agent1$ [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Blacklisted-agent2$ [NC]
RewriteRule .* - [F]

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_REFERER} !^http://www.olddomain.com [NC]
RewriteRule .* - [G]

RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/source2.html$
RewriteRule ^(.*)$ /dest2.html [R]

RewriteCond %{THE_REQUEST} ^/source3.html\?test=1$
RewriteRule .* /dest3.html [R]

RewriteCond %{ENV:npm_package_main} ^lib/middleware.js$
RewriteRule ^source4.html$ /dest4.html [R]

RewriteCond %{ENV:non_existing_var} !^lib/middleware.js$
RewriteRule ^source5.html$ /dest5.html [R]

RewriteCond %{QUERY_STRING} val
RewriteRule ^page1 page2 [R]

RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^path /path/%1/%2 [R,QSD]

RewriteCond %{QUERY_STRING} =var=val
RewriteRule source6\.html dest6.html [R,QSD]

RewriteCond "%{REQUEST_URI}" "=/source7.html"
RewriteRule '^(.*)$' '/dest7.html'