在access_log中,我有许多像这样的消息的Apache 2.2.4服务器:
::1 - - [15/May/2010:19:55:01 +0200] "OPTIONS * HTTP/1.0" 400 543 ::1 - - [15/May/2010:20:22:17 +0200] "OPTIONS * HTTP/1.0" 400 543 ::1 - - [15/May/2010:20:24:58 +0200] "OPTIONS * HTTP/1.0" 400 543 ::1 - - [15/May/2010:20:25:55 +0200] "OPTIONS * HTTP/1.0" 400 543 ::1 - - [15/May/2010:20:27:14 +0200] "OPTIONS * HTTP/1.0" 400 543
这些是在这个页面上解释的“内部虚拟连接”:
http://wiki.apache.org/httpd/InternalDummyConnection
该页面也遇到了我的主要问题:“在2.2.6及更早的版本中,在某些configuration中,这些请求可能会造成一个重量级的dynamic网页,并在服务器上造成不必要的负载。 您可以通过使用mod_rewrite来回应用特定的用户代理或IP地址访问时redirect。 “
那么,显然我不能使用UserAgent,因为我最小化了服务器签名,但我可以使用IP地址。 但是,我不知道应该使用RewriteCond和RewriteRule来查找IPv6地址:: 1。
这个运行的网站使用CodeIgniter,所以已经有了下面的.htaccess,我只需要添加它:
RewriteEngine on RewriteCond %{REQUEST_URI} ^/system.* RewriteRule ^(.*)$ /index.php?/$1 [G] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L]
任何想法如何写这个.htaccess规则?
解决:添加另一个规则使OPTIONS落在当前规则下,并按照Apache默认的方式进行处理。
RewriteEngine on RewriteCond %{REQUEST_URI} ^/system.* RewriteRule ^(.*)$ /index.php?/$1 [G] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REMOTE_HOST} !^::1$ RewriteRule ^(.*)$ /index.php?/$1 [L]
我从来不通过IPv6上的本地主机访问网站,所以这个工程很好。
RewriteCond %{REMOTE_HOST} ^::1$ RewriteRule ^OPTIONS http://www.google.com/ [L]
这是我最好的猜测,我确定的RewriteCond ,但不完全与RewriteRule
它将在REMOTE_HOST ::1上匹配,然后将任何以OPTIONS开头的URL的请求重写为www.google.com