سؤال

I have an AngularJS application running under a Tomcat 7 server, where the app lives in ~/tomcat/webapps/web-client/.

I'm trying to configure the server such that a refresh, or otherwise playing with the URL will redirect to http://server:8080/web-client/index.html.

Using Tuckey UrlRewrite, I have this in my urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite
    PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
    "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
    <rule>
       <from>/(.*)$</from>
       <to type="redirect">/web-client/index.html</to>
    </rule>
</urlrewrite>

This works for anything like server:8080/whatevergarbage, but not server:8080/web-client/moregarbage.

I've tried adding use-context in the urlrewrite.xml file, as well as turning on crossContext in the server.xml file:

Also added a base tag to index.html.

I'm pretty sure I just don't understand the problem completely...

هل كانت مفيدة؟

المحلول

Solution:

I misunderstood the way the url rewriting worked. I had installed the rewriter under ~/tomcat/webapps/ROOT/WEB-INF, when it really needed to be under the application folder: ~/tomcat/webapps/web-client/WEB-INF.

So, now URLs under server:8080/web-client/ are redirected correctly.

In case it helps someone else out in the future, this is my urlrewrite.xml file:

<urlrewrite use-context="false">
    <rule enabled="true">
        <note>Do not process URL ending at index.html</note>
        <from>/index.html$</from>
        <to last="true">-</to>
    </rule>
    <rule enabled="true">
        <note>Do not process URLs targeting assets</note>
        <from>/assets/</from>
        <to last="true">-</to>
    </rule>
    <rule enabled="true">
        <note>Do not process calls to restservice</note>
        <from>/restservice/</from>
        <to last="true">-</to>
    </rule>
    <rule enabled="true">
        <note>Do not process mocks</note>
        <from>/mocks/</from>
        <to last="true">-</to>
    </rule>
    <rule enabled="true">
        <note>Process any URL without 'index', send to /web-client/index.html</note>
        <from>^(?!index).*$</from>
        <to type="redirect">%{context-path}/index.html</to>
    </rule>
</urlrewrite>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top