【问题标题】:Domain issue with tomcattomcat的域问题
【发布时间】:2016-09-30 08:31:00
【问题描述】:

我在我的 VPS 上部署了一个基于 Java 的网站。它成功部署并正常工作。我已经定义了一个重定向规则来从根目录重定向到子文件夹。我现在面临的问题是,

如果我把 domain.com -> 重定向到 domain.com/pages/shopIndex(显示 页面正确)

当我把 www.domain.com -> 重定向到 www.domain.com/pages/shopIndex(显示 404)

我不理解这种奇怪的行为,因为我在 httpd.conf 中将 domain.com 的别名添加到 www.domain.com

这是我的虚拟主机文件的样子:

<VirtualHost 192.169.235.118:80>
  ServerName domain.parentDomain.in
  ServerAlias domain.com www.domain.com www.domain.parentDomain.in
  DocumentRoot /path_to/domain.com
  ServerAdmin admin@admin
  UseCanonicalName Off
  CustomLog /path_to/domain.parentDomain.in combined
</VirtualHost>

谁能帮我找到解决办法?

【问题讨论】:

    标签: java apache tomcat redirect


    【解决方案1】:

    我得到了这个问题的解决方案,server.xml 文件有 Alias 标签,我们可以将 Alias 放置在我们想要代表的主机上。

    这就是我解决问题的方法(在host 标签内的server.xml 中):

    <Alias>www.domain.com</Alias>
    

    【讨论】:

    • 如果你不关心它是什么,你不应该在 Tomcat 中设置主机名。只需使用默认主机即可。
    • 是的,我知道@ChristopherSchultz,但问题是最终用户可能会输入www.domain.com/domain.com,最终转换为http://www.domain.com/http://domain.com,由于这个apache tomcat可能无法获得正确的路径。另外我忘了告诉我在主机标记中的server.xml 文件中提到了 host=domain.com,这可能是它没有被重定向到正确路径的原因,我收到 404 错误。
    猜你喜欢
    • 2011-07-11
    • 2016-01-13
    • 1970-01-01
    • 2011-03-21
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 2011-04-29
    相关资源
    最近更新 更多