Apache重写规则改变了它不应该做的事情

cwdobuhd  于 2023-10-23  发布在  Apache
关注(0)|答案(1)|浏览(179)

我想设置一个Apache服务器,以便它将请求https://example.edu/rdemos/(.*)重定向到运行在端口3838上的闪亮服务器。其他网页应转到正常的代理服务器。
所以我在ssl.conf中有以下指令:

  1. RewriteEngine on
  2. RewriteRule ^/PP/(.*) https://example.com/PhysicsPlayground/$1
  3. <Location /rdemos>
  4. RedirectMatch permanent ^/rdemos$ /rdemos/
  5. RewriteEngine on
  6. RewriteCond %{HTTP:Upgrade} =websocket
  7. RewriteRule /rdemos/(.*) ws://localhost:3838/$1 [P,L]
  8. RewriteCond %{HTTP:Upgrade} !=websocket
  9. RewriteRule /rdemos/(.*) http://localhost:3838/$1 [P,L]
  10. ProxyPass http://localhost:3838/
  11. ProxyPassReverse http://localhost:3838/
  12. # Header edit Location ^/ /rdemos/
  13. </Location>

这会正确地重定向/rdemos下的文件,因此https://example.com/rdemos/index.html会像预期的那样转到shiny服务器(端口3838)。
但是,其他文件会被随机重定向。所以https://example.com/PP/demo.html被路由到https://example.com/rdemos/PhysicsPlayground/demo.html(它不存在)。
我做错了什么?
我使用Apache/2.4.37(Red Hat Enterprise Linux)OpenSSL/1.1.1k mod_fcgid/2.3.9 SVN/1.10.2 mod_wsgi/4.6.4 Python/3.6 mod_apreq2-20101207/2.8.1

nwnhqdif

nwnhqdif1#

我不会尝试混合使用mod_alias和mod_rewrite指令。把所有东西都转换成mod_rewrite,因为你需要使用它。
重定向重写规则应该使用[R=301,L]
我不会尝试将ProxyPass与带有P标志的重写规则混合在一起。使用重写规则。
在重写规则时使用^/?具有更好的可移植性,因此它们可以在.htaccess中工作而无需修改。
您永远不需要多次指定RewriteEngine on
ProxyPassReverse应指定该值。

  1. RewriteEngine on
  2. RewriteRule ^/?PP/(.*) https://example.com/PhysicsPlayground/$1 [R=301,L]
  3. RewriteRule ^/?rdemos$ /rdemos/ [R=301,L]
  4. RewriteCond %{HTTP:Upgrade} =websocket
  5. RewriteRule ^/?rdemos/(.*) ws://localhost:3838/$1 [P,L]
  6. RewriteCond %{HTTP:Upgrade} !=websocket
  7. RewriteRule ^/?rdemos/(.*) http://localhost:3838/$1 [P,L]
  8. ProxyPassReverse /rdemos/ http://localhost:3838/
展开查看全部

相关问题