以下是我httpd.conf
的摘录。我希望在[2]
捕获所有不匹配的请求,并将代理转发到http://localhost:8585
。但是,所有链接都已发送到http://localhost:8585/var/ww/html/
DocumentRoot "/var/www/html"
<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine on
RewriteRule testing/(.*) http://localhost:8585/mytesting/$1 [P,L] # [1]
RewriteRule (.*) http://localhost:8585/$1 [P,L] # [2] Catch all Rule
</Directory>
以下是我尝试的一些测试和重写后的结果
好结果
http://localhost/testing/
=&gt; http://localhost:8585/mytesting/
[3]
http://localhost/testing/goodOne
=&gt; http://localhost:8585/mytesting/goodOne
[4]
糟糕的结果
http://localhost:8080/testing
=&gt; http://localhost:8585/var/www/html/testing
[5]我希望http://localhost:8585/testing
http://localhost:8080/
=&gt; http://localhost:8585/var/www/html/
[6]我希望http://localhost:8585/
问题很明显,重写后的最后RewriteRule
前置DocumentRoot
(/ var / www / html /)。我做错什么了吗?或者这是预期的行为?我如何修复/解决此问题以获得我的预期结果?
RewriteLog
和RewriteLogLevel 2
[3]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing/' -> 'http://localhost:8585/mytesting/'
::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped URI in per-dir context for proxy, http://localhost:8585/mytesting/ -> http://localhost:8585/mytesting/
::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput with http://localhost:8585/mytesting/
::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead with proxy request proxy:http://localhost:8585/mytesting/ [OK]
[4]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing/goodOne' -> 'http://localhost:8585/mytesting/goodOne'
::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped URI in per-dir context for proxy, http://localhost:8585/mytesting/goodOne -> http://localhost:8585/mytesting/goodOne
::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput with http://localhost:8585/mytesting/goodOne
::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead with proxy request proxy:http://localhost:8585/mytesting/goodOne [OK]
[5]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing' -> 'http://localhost:8585/var/www/html/testing'
::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped URI in per-dir context for proxy, http://localhost:8585/var/www/html/testing -> http://localhost:8585/var/www/html/testing
::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput with http://localhost:8585/var/www/html/testing
::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead with proxy request proxy:http://localhost:8585/var/www/html/testing [OK]
[6]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/' -> 'http://localhost:8585/var/www/html/'
::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped URI in per-dir context for proxy, http://localhost:8585/var/www/html/ -> http://localhost:8585/var/www/html/
::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput with http://localhost:8585/var/www/html/
::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead with proxy request proxy:http://localhost:8585/var/www/html/ [OK]
答案 0 :(得分:0)
您的正则表达式在“测试”之后需要“ / ”,如果这是可选的,如您的第二个示例所示,请更新您的正则表达式以反映这一点,方法是添加?,使用%{REQUEST_URI}而不是不必要的(。*)+ $ 1 组合也是一种好习惯,例如。
input()