With Apache, I'm trying to set up a rewrite rule which will be included in several virtual hosts. Actually, this rule file is included in 2 vhost.
The first vhost contains only this rewrite rule (and it works) and is acting as a reverse proxy for Nginx :
RewriteEngine On
Include /etc/apache2/bad-referers
The other one contains a Wordpress with W3 Total Cache plugin with its Apache conf and the default WP .htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain.tld$
RewriteRule ^(.*) http://domain.tld/$1 [R=301,L,QSA]
Include /etc/apache2/bad-referers
Include /var/www/d/domain.tld/w3tc.conf
The bad-referers, in this case is never matched, while this rule ended with [F,L]. The domain name rewriting and W3 Total Cache rules works well. I really do not understand.
Does the order or placement of Include directives matter ? May I have to put the content of all those files in the vhost directive ? Or the RewriteBase ?
The (almost) full vhost via /server-info :
In file: /etc/apache2/sites-enabled/domain.tld
1: <VirtualHost *:80>
7: <Directory /var/www/d/domain.tld/html/>
14: RewriteEngine On
16: RewriteCond %{HTTP_HOST} !^domain.tld$
17: RewriteRule ^(.*) http://domain.tld/$1 [R=301,L,QSA]
In file: /etc/apache2/bad-referers
2: RewriteEngine on
5: RewriteCond %{HTTP_REFERER} 4webmasters\.org [NC,OR]
104: RewriteCond %{HTTP_REFERER} youporn-forum\.uni\.me [NC]
105: RewriteRule ^.* - [F,L]
In file: /var/www/d/domain.tld/w3tc.conf
191: RewriteEngine On
192: RewriteBase /wp-content/cache/minify/
193: RewriteRule /w3tc_rewrite_test$ ../../plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 [L]
194: RewriteCond %{HTTP:Accept-Encoding} gzip
195: RewriteRule .* - [E=APPEND_EXT:.gzip]
196: RewriteCond %{REQUEST_FILENAME}%{ENV:APPEND_EXT} -f
197: RewriteRule (.*) $1%{ENV:APPEND_EXT} [L]
198: RewriteRule ^(.+/[X]+\.css)$ ../../plugins/w3-total-cache/pub/minify.php?test_file=$1 [L]
199: RewriteRule ^(.+\.(css|js))$ ../../plugins/w3-total-cache/pub/minify.php?file=$1 [L]
207: RewriteEngine On
208: RewriteBase /
209: RewriteCond %{HTTP:Accept-Encoding} gzip
210: RewriteRule .* - [E=W3TC_ENC:_gzip]
211: RewriteCond %{REQUEST_METHOD} !=POST
212: RewriteCond %{QUERY_STRING} =""
213: RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
214: RewriteCond %{HTTP_USER_AGENT} !(W3\ Total\ Cache/0\.9\.3) [NC]
215: RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html%{ENV:W3TC_ENC}" -f
216: RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html%{ENV:W3TC_ENC}" [L]
In file: `/etc/apache2/sites-enabled/domain.tld`
: </Directory>
: </VirtualHost>