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

时间:2016-05-25 12:20:37

标签: java wildfly-8

我有两个域名,

  • example.com
  • example1.com

两者都指向wildfly-8服务器的相同ip-adress。

我可以配置wildfly,所以当用户来到example1.com时,wildfly会将他重定向到example.com吗?

1 个答案:

答案 0 :(得分:0)

虽然不是原始问题的答案(因为它只是通过更改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:)

相关问题