java - 是否可以在没有 war 文件的情况下使用 JBoss Rewrite?

标签 java maven url-rewriting jboss

是否可以在 war 文件之外使用 rewrite.properties 和 jboss-web.xml?

目前,我将这两个文件放入我的 war 文件中的 WEB-INF 中,并且它按预期工作。但是集成测试(使用 Maven)将会失败,因为它们被重定向到真实的网站,而不是使用测试中的版本。

如果重要的话,我的域直接指向 war 文件的上下文路径。我正在使用 JBoss 7.1.1。

我尝试将这两个文件放在服务器上的 war 文件旁边,但这不起作用。

最佳答案

我将配置移至standalone.xml(对于OpenShift 用户,它位于文件夹.openshift/config 中)。关于 URL 重写的 XML 格式的文档非常少,因此我将我的配置显示为示例代码。

    <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host"
               native="false">
        <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
        <virtual-server name="default-host" enable-welcome-root="false">
            <alias name="localhost"/>
            <!-- Redirect all subdomains including naked domain to www subdomain. -->
            <!-- RewriteCond %{HTTP_HOST} !^www\.example\.org$ [NC] -->
            <!-- RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L] -->
            <rewrite pattern="^(.*)$" substitution="http://www.example.org$1" flags="R=301,L">
                <condition test="%{HTTP_HOST}" pattern="!^www\.example\.org$" flags="NC"/>
            </rewrite>

            <!-- Redirect from HTTP to HTTPS. -->
            <!-- RewriteCond %{HTTP:X-Forwarded-Proto} http -->
            <!-- RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L] -->
            <rewrite pattern=".*" substitution="https://%{HTTP_HOST}%{REQUEST_URI}" flags="R,L">
                <condition test="%{HTTP:X-Forwarded-Proto}" pattern="http" flags="NC"/>
            </rewrite>
        </virtual-server>
    </subsystem>

也许这两个规则可以优化,但我在重定向周期方面遇到了问题,这对我有用。

关于java - 是否可以在没有 war 文件的情况下使用 JBoss Rewrite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19464632/

相关文章:

java - 什么是良好的做法 map.remove 并放置值或只是覆盖现有值

java - Java 的 Compass/sass 替代品

asp.net - IIS URL 重写规则使用条件

java - 使用jetty如何重写Eclipse RAP应用程序的参数?

tomcat - Nginx - 如何从 header 中获取值并将其设置到 cookie 中?

java - session 持久性与值(value)栈维护之间的区别

java - 使用 thymeleaf 和 bootstrap 未在验证表单上应用样式

java - GWT 中 ScriptInjector 的使用

java - maven-dependency-plugin 忽略 outputDirectory 配置

java - maven Surefire-junit47 未运行 JUnit4 测试