我正在将URL重写功能从apache mod_rewrite迁移到Tomcat 8的RewriteValve。 我有在负载均衡器后面运行的apache web服务器。 有些URL会根据域名重写。
RewriteCond %{SERVER_NAME} ^xyz.com RewriteRule /pattern$ /substitution [L]在Apache的mod_rewrite中,SERVER_NAME变量工作正常。 但是在tomcat 8中,变量返回的是机器的IP地址而不是服务器名称。
I am migrating URL rewrite functionality from apache mod_rewrite to Tomcat 8's RewriteValve. I have apache web servers running behind load balancer. There are some URLs getting rewritten based on the domain name.
RewriteCond %{SERVER_NAME} ^xyz.com RewriteRule /pattern$ /substitution [L]In Apache's mod_rewrite, the SERVER_NAME variable was working fine. However in tomcat 8 the variable is returning the IP address of the machine instead of the server name.
最满意答案
在Tomcat的SSI文档中的 Variables部分下
SERVER_NAME服务器的主机名或IP地址。
HTTP_HOST客户端请求的网站。
在RewriteRules中使用HTTP_HOST变量修复了我的问题。
Under Variables section in Tomcat's SSI document
SERVER_NAME The server's hostname or IP address.
HTTP_HOST The web site that the client requested.
Using HTTP_HOST variable in RewriteRules fixed my problem.
更多推荐
发布评论