-
1. Re: how to use rewrite url in jboss eap 7.0
jewellgm Jun 26, 2019 4:17 PM (in response to anuj_kumar)You can configure a rewrite filter within the undertow subsystem, or you can add a undertow-handlers.conf file to the WEB-INF directory of your webapp.
For the direct subsystem configuration, the "host" element can contain "filter-ref" children. I don't know if you can pass the capture groups to the referenced filter. For example:
<host name="default-host" alias="localhost">
<filter-ref name="rewriteFilter" predicate="regex('/my-app/scripts/(.*)')" />
</host>
<filters>
<rewrite name="rewriteFilter" target="/scripts/${1}" /> <--- I don't know how to pass the capture group into here. There is a good chance this wouldn't work.
</filters<
If you put it in the undertow-handlers.conf file, I believe you would want something like the following:
regex('/my-app/scripts/(.*)') -> rewrite('/scripts/${1}')
-
2. Re: how to use rewrite url in jboss eap 7.0
anuj_kumar Jul 4, 2019 6:19 AM (in response to jewellgm)Hi jewellgm
Now, i have undertow-handlers.conf under web-inf directory and i have below line inside file
regex('/aa-web-corp/scripts/(.*)') -> rewrite('/scripts/${1}')
But this seems not to be working. Any idea. I also tried by direct subsystem configuration
Also what is ${1} ?
-
3. Re: how to use rewrite url in jboss eap 7.0
loganheights Jul 9, 2019 3:37 PM (in response to anuj_kumar)I think jewellgm was close. I have been trying to do the same thing as anuj_kumar, stripping the context, but I don't want to use the undertow-handler.conf. Here's how mine ended up:
<server>
.
.
.
<host name="default-host" alias="localhost">
<filter-ref name="removeMe" predicate="regex('/removeMe(.*)')" />
</host>
</server>
<filters>
<expression-filter name="removeMe" expression="path-prefix('/removeMe') -> redirect('$${remaining}')" />
</filters>
The $$ are needed per the following link and it now works. When I enter http://someURL/removeMe/blah/yada, I'm redirected to http://someURL/blah/yada.
How to use a ${} value in an undertow expression filter with CLI - Red Hat Customer Portal
anuj_kumar - the ${1} is the contextual value from the regex command (.*). In your case, it's whatever comes after "scripts/".
-
4. Re: how to use rewrite url in jboss eap 7.0
anuj_kumar Jul 11, 2019 5:49 AM (in response to loganheights)Hi loganheights
I am using jboss eap 7.0 . I am getting error WFLYCTL0211: Cannot resolve expression 'path-prefix'. whats your thoughts on this.
Thanks
Anuj
-
5. Re: how to use rewrite url in jboss eap 7.0
loganheights Jul 11, 2019 9:49 AM (in response to anuj_kumar)Can you post the undertow subsystem from your standalone xml config file?
I'm using EAP 7.2 but I'm pretty sure it should work the same since EAP 7.0.
-
6. Re: how to use rewrite url in jboss eap 7.0
anuj_kumar Jul 12, 2019 8:50 AM (in response to loganheights)Hi loganheights
PFB the undertow confurations
<subsystem xmlns="urn:jboss:domain:undertow:3.1" instance-id="jboss1">
<buffer-cache name="default"/>
<server name="default-server">
<ajp-listener name="ajp" socket-binding="ajp"/>
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost">
<location name="/" handler="securityimages"/>
<location name="/aa-web-corp/styles/" handler="styles"/>
<location name="/aa-web-corp/scripts/" handler="scripts"/>
<location name="/scripts/" handler="scripts"/>
<location name="/aa-web-corp/images/" handler="images"/>
<filter-ref name="removeMe" predicate="regex('/aa-web-corp/scripts/(.*)')"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="securityimages" path="${jboss.home.dir}/securityimages"/>
<file name="styles" path="${jboss.home.dir}/aa-web-corp/styles"/>
<file name="scripts" path="${jboss.home.dir}/aa-web-corp/scripts"/>
<file name="images" path="${jboss.home.dir}/aa-web-corp/images"/>
</handlers>
<filters>
<expression-filter name="removeMe" expression="path-prefix('/aa-web-corp') -> redirect('$${/scripts/${1}')" />
<response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
</filters>
</subsystem>
-
7. Re: how to use rewrite url in jboss eap 7.0
anuj_kumar Jul 12, 2019 8:54 AM (in response to anuj_kumar)Just to reiterate, I want to rewrite url "/aa-web-corp/scripts/*" to "/scripts/* But below error i am getting
18:19:07,747 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 61) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "undertow"),
("configuration" => "filter"),
("expression-filter" => "removeMe")
]) - failure description: "WFLYCTL0211: Cannot resolve expression 'path-prefix('/aa-web-corp') -> redirect('$${/scripts/${1}')'"
18:19:07,747 INFO [org.jboss.modcluster] (ServerService Thread Pool -- 64) MODCLUSTER000001: Initializing mod_cluster version 1.3.2.Final-redhat-1
-
8. Re: how to use rewrite url in jboss eap 7.0
loganheights Jul 15, 2019 10:07 AM (in response to anuj_kumar)Ok I think I see the problem...need to change this
<expression-filter name="removeMe" expression="path-prefix('/aa-web-corp') -> redirect('$${/scripts/${1}')" />
to this
<expression-filter name="removeMe" expression="path-prefix('/aa-web-corp') -> redirect('$${remaining}')" />
"remaining" is a keyword that Undertow (?) recognizes and handles.
If this solves the issue, please mark it was the accepted answer. Thanks!