我在tomcat前面使用apache,所以我可以使用mod_proxy将请求从域重定向到tomcat url。我在服务器上遇到了一个问题,在使用子域时,它想要返回到基本域。有没有办法将example.com/foo的所有请求重定向到foo.example.com?Apache重定向来自域名+路径的请求
<VirtualHost *:80>
ServerName example.com/app
ProxyPreserveHost Off
ProxyPass/http://app.example.com:8080/AppName/
ProxyPassReverse/http://app.example.com:8080/AppName/
</VirtualHost>
上面的示例不起作用。我推测这是因为我无法在服务器名称中包含路径。
下面是我根据接受的答案标记的工作版本。
<VirtualHost *:80>
ServerName example.com/app
ProxyPreserveHost Off
ProxyPass/http://app.example.com:8080/AppName/
ProxyPassReverse/http://app.example.com:8080/AppName/
# Rewrite all request from example.com/foo to foo.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/foo/?(.*) http://foo.example.com/$1 [R,L]
</VirtualHost>
我正在努力如何使用重写,因为这实际上不是一个Apache网站。 Apache实际上只是坐在前面,并将请求转发到一个tomcat应用程序url。 – ryandlf
划痕。这工作。我没有在.htaccess中包含重写(因为我没有),而是直接将其包含在虚拟主机中。我将在原始帖子中包含正在运行的虚拟主机标签。 – ryandlf