我正在尝试编写将在新服务器上提供文件的规则,同时将不存在的文件代理到旧服务器。代理规则工作正常,将丢失的文件和目录发送到旧服务器。
我遇到的问题是 new-server.example.com/blah (/blah/ 存在于新服务器上)被传递到代理规则并路由到旧服务器。
尝试跳过的原因是因为 new-server.example.com/blah 落入“代理部分”并通过 new-server.example.com/blah/index.php。新服务器上不存在 Index.php,但 index.html 存在。“代理部分”不遵循 DirectoryIndex 中的所有索引文件可能性,它只查看第一个。
所以我最终得到错误消息,“在此服务器上找不到请求的 URL /blah/index.php”。
这怎么写才能真正起作用? - 谢谢。
RewriteEngine On
# skip, proxy section
RewriteCond /var/www/html%{REQUEST_FILENAME} -f [OR]
RewriteCond /var/www/html%{REQUEST_FILENAME} -d
RewriteRule .? - [S=4]
# proxy section
RewriteCond /var/www/html%{REQUEST_FILENAME} !-f
RewriteCond /var/www/html%{REQUEST_FILENAME} !-d
RewriteRule ^/(.*) http://old-server.example.com/$1 [P]
ProxyPassReverse / http://old-server.example.com/
# rewrite log
pass through /index.php
init rewrite engine with requested uri /
applying pattern '.?' to uri '/'
RewriteCond: input='/var/www/html/' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/' pattern='-d' => matched
pass through /
init rewrite engine with requested uri /index.php
applying pattern '.?' to uri '/index.php'
RewriteCond: input='/var/www/html/index.php' pattern='-f' => matched
pass through /index.php
init rewrite engine with requested uri /blah/
applying pattern '.?' to uri '/blah/'
RewriteCond: input='/var/www/html/blah/' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/blah/' pattern='-d' => matched
pass through /blah/
init rewrite engine with requested uri /blah/index.php
applying pattern '.?' to uri '/blah/index.php'
RewriteCond: input='/var/www/html/blah/index.php' pattern='-f' => not-matched
RewriteCond: input='/var/www/html/blah/index.php' pattern='-d' => not-matched
applying pattern '^/(.*)' to uri '/blah/index.php'
RewriteCond: input='/var/www/html/blah/index.php' pattern='!-f' => matched
RewriteCond: input='/var/www/html/blah/index.php' pattern='!-d' => matched
rewrite '/blah/index.php' -> 'http://old-server.example.com/blah/index.php'
forcing proxy-throughput with http://old-server.example.com/blah/index.php
go-ahead with proxy request proxy:http://old-server.example.com/blah/index.php [OK]