Search code examples
url-rewritingtomcat7angular5

How to integrate tucky URL rewrite with Angular and Tomcat 7


iam using a Tomcat 7 server and copied my angular 5 project into the ROOT directory. Deep links does not work at the moment. I have tried to use tucky URL rewrite.

I created a WEB-INF folder in the ROOT directory. Therein i created a folder named lib and saved the file "urlrewritefilter-4.0.3 .jar" there.

The WEB-INF folder also contain a urlrewrite.xml file and a web.xml.

I hope that someone may help me to solve this issue.

    <?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">
<!--
Configuration file for UrlRewriteFilter
http://www.tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule match-type="regex">
    <note>
        Redirect all http requests to angulars index. html except /tcc/* cause its needed for backend operations
    </note>
    <condition name="request-uri" operator="notequal">^/tcc/*</condition>
    <from>^.*$</from>
    <to type="permanent-redirect" last="true">http://localhost:8080</to>
</rule>
</urlrewrite>

web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>

Solution

  • I was not able to get Tucky to run. I changed the routing method of Angular to the # routing to fit my needs. Another working aproach to get this running is to update to tomcat 8 and use the inbuild mechanisms.