【问题标题】:Is it possible to use JBoss Rewrite without war-file?是否可以在没有战争文件的情况下使用 JBoss Rewrite?
【发布时间】:2013-10-28 04:20:31
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: java maven url-rewriting jboss


    【解决方案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>
    

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

    【讨论】:

    • 好例子,我正在尝试找到一个将 http_request 方法从 GET 更改为 POST 的示例,因为您可能猜到几乎不可能找到任何好例子:-/
    猜你喜欢
    • 2012-12-31
    • 2011-01-28
    • 1970-01-01
    • 2018-08-06
    • 2014-06-16
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多