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

时间:2013-10-19 09:45:42

标签: java maven url-rewriting jboss

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

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

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

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

1 个答案:

答案 0 :(得分:1)

我将配置移动到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>

也许这两条规则可以优化,但我在重定向周期出现问题,这对我有用。

相关问题