Apache-2.2
包含的重寫規則不匹配
使用 Apache,我正在嘗試設置一個重寫規則,該規則將包含在多個虛擬主機中。實際上,這個規則文件包含在 2 vhost 中。
第一個 vhost 僅包含此重寫規則(並且它有效)並充當 Nginx 的反向代理:
RewriteEngine On Include /etc/apache2/bad-referers
另一個包含一個帶有 W3 Total Cache 外掛的 Wordpress,它的 Apache conf 和預設的 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
在這種情況下,bad-referers 永遠不會匹配,而此規則以
$$ F,L $$. 域名重寫和 W3 Total Cache 規則執行良好。我真的不明白。 Include 指令的順序或位置是否重要?我可以將所有這些文件的內容放在 vhost 指令中嗎?還是 RewriteBase ?
通過 /server-info 的(幾乎)完整虛擬主機:
在文件中:
/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]
在文件中:
/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]
在文件中:
/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>
使用另一種方法解決,SetEnvIf & access denied。
<IfModule mod_setenvif.c> SetEnvIfNoCase Referer 4webmasters\.org spambot=yes Order allow,deny Allow from all Deny from env=spambot </IfModule>