为什么SERVER

编程入门 行业动态 更新时间:2024-10-23 19:20:26
为什么SERVER_NAME变量在tomcat 8 URL Rewrite中返回不正确的值?(Why is SERVER_NAME variable returning incorrect value in tomcat 8 URL Rewrite?)

我正在将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.

更多推荐

本文发布于:2023-07-25 22:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SERVER

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!