1

I have IIS with URL Rewrites acting as a reverse proxy to Apache Tomcat.

example.com/app/ redirects to example.com:8080/app/. Port 80 redirects to port 8080 on the same server.

If I go to example.com/app/ it works as expected. However, if I go to example.com/app (without the trailing slash), it results in a 404 error.

The pattern I'm matching for the Inbound Rule is ^app/(.*). Then the action rewrites to the URL http://127.0.0.1:8080/app/{R:1}.

Any suggestions on how to get this to work without the trailing slash?

1

I had a similar issue and manage to fix it by creating two rules

  1. 301 Redirect

search pattern: ^app$

redirect URL: app/

  1. rewrite

search pattern: ^app/(.*)

rewrite URL: http://127.0.0.1:8080/app/{R:1}

0

To elaborate on Thomas's answer, here is the config file after the rules have been created:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="ReverseProxyInboundRule2" stopProcessing="true">
                    <match url="^app$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="app/" />
                </rule>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8080/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
0

I believe it could work with a solution I used for a similar issue. In your case, the search pattern would be:

^app(/?|/.*)$

and the Rewrite URL would be:

http://127.0.0.1:8080/app{R:1}

Notice that there is no

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.