gpt4 book ai didi

java - 我可以配置 Wildfly 从一个域名重定向到另一个域名吗?

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:52 26 4
gpt4 key购买 nike

我有两个域名,

  • example.com
  • example1.com

两者都指向 wildfly-8 服务器的相同 IP 地址。

我可以配置 wildfly,以便当用户访问 example1.com 时,wildfly 将他重定向到 example.com 吗?

最佳答案

虽然不完全是原始问题的答案(因为它不能通过仅更改 wildfly 配置来工作),但我是这样解决的:

我一直在使用ocpsoft rewrite 。通过重写,您可以使 URL 看起来更漂亮,事实上,我已经将它用于此目的相当长一段时间了。但直到最近我才发现它不仅适用于路径,还适用于域部分。

您需要做的就是添加依赖项:

<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>3.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>3.4.1.Final</version>
</dependency>

实现配置提供程序:

@RewriteConfiguration
public class RewriteConfigurationProvider extends HttpConfigurationProvider {

@Override
public int priority() {
return 10;
}

@Override
public Configuration getConfiguration(final ServletContext context) {

return ConfigurationBuilder.begin()

.addRule()
.when(Direction.isInbound().and(Domain.matches("www.somedomain.de")).and(Path.matches("{path}")))
.perform(Redirect.permanent("http://www.someotherdomain.de{path}"))
.where("path").matches(".*")

.addRule(Join.path("/prettypath").to("/pretty.xhtml").withInboundCorrection())
.addRule(Join.path("/prettypathwithparam/{id}").to("pretty.xhtml").withInboundCorrection());

}

}

就是这样!

我什至更喜欢这个,而不是重新配置 Wildfly,因为它更强大,如果你需要的话。例如,您可以让应用程序逻辑决定是否重定向请求、计算每个域上传入访问者的数量、动态使用子域等等。

披露...:我不以任何方式隶属于 ocpsoft,除了我是他们的库的快乐用户:)

关于java - 我可以配置 Wildfly 从一个域名重定向到另一个域名吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com