https://www.example.com I wa" /> https://www.example.com I wa" /> https://www.example.com I wa"/>

How to use environment variable in urlrewrite.xml of tomcat rewrite file

306 Views Asked by At

I have a urlrewrite.xml which I want to use to redirect an url

    <rule>
        <from>/http</from>
        <to redirect="true">https://www.example.com</to>
    </rule>

I want the example.com to be coming from a java system variable which I have set at startup, however it didnt work. This is the code I modified to use the java system variable 'exampleurl'

    <rule>
        <from>/http</from>
        <to redirect="true">${exampleurl}</to>
    </rule>
1

There are 1 best solutions below

2
Manonandan S K On

It is just an alternative What I have tried.
This will help if you use same thing multiple times in the same file.

[<!ENTITY exampleurl "127.0.0.1">]

Add the above line to DOCTYPE line like this.

<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd" [<!ENTITY exampleurl "127.0.0.1">]>

Use &exampleurl; like below:

<rule>
    <from>/http</from>
    <to redirect="true">&exampleurl;</to>
</rule>