Search code examples
javawebhttpsjbosswildfly

http to https conditional redirect in jboss/wildfly


JBoss/Wildfly => standalone.xml

Redirect http to https only if the request url contains a domain name. If the web site access from ip address do not redirect.

http://x.x.x.x:8080 -> do not redirect

http://xx.example.com -> redirect to https://xx.example.com

I am using http to https redirect using the below code in standalone.xml

<server name="default-server">
    <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
    <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
    <host name="default-host" alias="localhost">
        <filter-ref name="http-to-https" predicate="equals(%p,8080)"/>
    </host>
</server>
<filters>
    <rewrite name="http-to-https" target="https://%v%U%q" redirect="true"/>
</filters>

But in this case redirect all request from ip or domain name if port is 8080.

http://x.x.x.x:8080 -> redirecting to https://x.x.x.x:8080

http://xx.example.com -> redirecting to https://xx.example.com

But i do not redirect if request from ip, only redirect from domain name.

I am using http to https redirect using the below code in standalone.xml. But its not redirect in both conditions.

<server name="default-server">
    <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
    <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
    <host name="default-host" alias="localhost">
        <filter-ref name="http-to-https" predicate="regex(pattern='/http://(.*).example.com/g') and equals(%p,8080)"/>
    </host>
</server>
<filters>
    <rewrite name="http-to-https" target="https://%v%U%q" redirect="true"/>
</filters>

EDIT

proxy server forward 80 -> 8080. (i.e http://xx.example.com -> http://xx.example.com:8080)

Also i tried with this, but its not redirect in both conditions.

<filter-ref name="http-to-https" predicate="regex(pattern='http://(.*).example.com', value=%U, full-match=false) and equals(%p,8080)"/>

Thanks


Solution

  • Finally i got the solution

    <filter-ref name="http-to-https" predicate="regex(pattern='example', value=%v, full-match=false) and equals(%p,8080)"/>
    

    http://x.x.x.x:8080 -> do not redirect

    http://xx.example.com -> redirect to https://xx.example.com