Reputation: 20889
We moved (or renamed) our webapplication from http://domain.tld/webapp/...
to http://domain.tld/ourWebapp/...
Now we want to redirect old urls to the new one - Most redirect solutions are handled inside the application. This however won't work, because with the wrong war-name given, the webapp is not triggered at all.
Is there a way to add redirects on the - let's say - server level, instead of handling it from within the application? (We don't want to deploy a "redirect application" listening on the old war-name.)
I found this documentation: http://www.jboss.org/jbossweb/modules/rewrite.html but it seems outdated, as it still talkes about server.xml
(there is none in JBOSS AS 7.1). All the mentioned elements aren't there either and not supported it seems...
After a lot of testing, I figured out, that this is possible INSIDE the standalone.xml, right in the virtual-server subsystem. However, there are still some Issues:
Whats working so far: The following entry leads to a forward as expected:
<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="true">
<alias name="localhost"/>
<rewrite pattern="^/webapp/(.*?)$" substitution="/myWebapp/$1" flags="R=301,L">
</rewrite>
</virtual-server>
</subsystem>
The (outdated) docu for doing rewrites with jboss (http://www.jboss.org/jbossweb/modules/rewrite.html) states, that there are several environmnet variables that can be used.
I noticed, that the ${HTTP_}
Variables are working, but using anything else gives me a 'java.lang.IllegalArgumentException'.
What I tried (and need to achieve):
<rewrite pattern="^/webapp/(.*?)$" substitution="${SERVER_PROTOCOL}://${SERVER_ADDR}:${SERVER_PORT}/myWebapp/$1" flags="R=301,L">
So basically a redirect that works independent of protocol and/or hostname.
I tried it with a "relative" Redirect (substitution="/myWebapp/$1"
) - This worked, but does not keep the port (requests on http://ip:8080/webapp/
are forwarded to http://ip/myWebapp/
)
Any ideas on this?
Upvotes: 2
Views: 7526
Reputation: 186
There's some explanation & examples here as well, if you have access to the RedHat site:
https://access.redhat.com/site/solutions/189423
JBoss EAP6 provided Global Rewrite valve which can be enabled in the "web" subsystem of your configuration as following: For redirecting all http requests coming for localhost:8080/MXBeanDemo should be redirected to "www.yahoo.com/"
<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="true">
<alias name="localhost"/>
<alias name="example.com"/>
<rewrite pattern="^/MXBeanDemo(.*)" substitution="http://www.yahoo.com" flags="R"/> <!-- NOTICE -->
</virtual-server>
</subsystem>
For redirecting localhost:8080/Abcd to localhost:8080/Wxyz
<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="true">
<alias name="localhost"/>
<alias name="example.com"/>
<rewrite pattern="^/Abcd(.*)" substitution="/Wxyz" flags="R"/> <!-- NOTICE -->
</virtual-server>
</subsystem>
Upvotes: 0
Reputation: 20889
Finally got it:
<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="true">
<alias name="localhost"/>
<rewrite pattern="^/webapp/(.*?)$" substitution="/myWebapp/$1" flags="R=301,L">
</rewrite>
</virtual-server>
</subsystem>
is working as expected and keeping the port. (Dunno, why it did not work on the first try, maybe didnt restart the server properly, etc...)
Upvotes: 2