6 Replies Latest reply on Nov 19, 2014 6:47 PM by partlycloudy

    Using Tomcat URL rewrite valve

    partlycloudy

      http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html

       

      Looks like the latest version of Tomcat has added support for URL rewriting similar to Apache mod_rewrite

       

      I can't seem to find any documentation other than the page above.

       

      Has anyone used this to, for example, rewrite APEX URLs from http://host:port/apex/... to http://host:port/pls/apex ?  Where should we put the RewriteCond and RewriteRule directives?

       

      Thanks

        • 1. Re: Using Tomcat URL rewrite valve
          jariola

          Hi,

           

          I did see your other post.

          https://community.oracle.com/thread/3629974?sr=stream&ru=417226

           

          Try rename ords.war to pls#apex.war in Tomcat webapps folder

           

          That should give you url

          http://host:port/pls/apex

           

          Regards,

          Jari

          • 2. Re: Using Tomcat URL rewrite valve
            partlycloudy

            Nope that didn't work.

             

            1.  $CATALINA_HOME/bin/shutdown.sh

            2. mv ords.war pls#apex.war

            3. $CATALINA_HOME/bin/startup.sh

             

            Now when I go to http://host:port/pls/apex I get This installation has not yet been configured


            So I do $JAVA_HOME/bin/java -jar pls#apex.war and I get a error stack WARNING: File path syntax error: ILLEGAL_CHARACTER, path: .... because of the # in the filename.

             

            Any other ideas? The Tomcat rewrite valve looks promising, but not sure how to use it with APEX/ORDS

            • 3. Re: Re: Using Tomcat URL rewrite valve
              jariola

              Hi,

               

              First configure ords.war.

               

              Then stop Tomcat and rename ords.war to pls#apex.war.

              Start Tomcat and go URL

              http://host:port/pls/apex  
              

               

              You should then see "error" that say where war file try locate config files.

              Stop Tomcat and copy ords config file to path you see in "error".

              Start Tomcat and try URL again.

               

              Regards,

              Jari

              • 4. Re: Using Tomcat URL rewrite valve
                ABD - DBA

                I just went though this, spent about two days trying to figure out how to do with only tomcat and gave up.  I found and used urlrewrite..  The instructions are right on main page but are vague.  I've given "hints" below.  My info assumes you renamed ords.war to apex.war.   I tried to post full details of my exploits/trials/troubles using the Oracle blog but it errored out.

                 

                http://tuckey.org/urlrewrite/

                 

                Step 1 say to place the file in WEB-INF/lib.  For Tomcat, WEB-INF is the Tomcat application directory, mine was /opt/apache-tomcat-7.0.56.   Place in the <tomcat_app_dir>/lib directory.

                 

                Step 2 says to edit the web.xml file, adding the config text for urlrewrite.  This file is located in <tomcat_app_dir>/ROOT/WEB-INF  Copy text and paste just above the </web-app> tag at the bottom of the <tomcat_app_dir>/ROOT/WEB-INF/web.xml file.

                 

                Step 3 talks about editing urlrewite.xml file, which doesn't exist.  You must create this file, in the same directory, <tomcat_app_dir>/ROOT/WEB-INF. The following is the contents of mine.

                 

                <urlrewrite use-query-string="true">

                                <note>

                                 rewrite from /pls/apex to pls

                                </note>

                       <rule>

                            <from>/pls/apex/f\?p(.*)</from>

                            <to type="redirect">/apex/f?p$1</to>

                        </rule>

                </urlrewrite>

                 

                You can check that urlrewite is working by accessing the admin/test page from the localhost....<servername>:8080/rewrite-status.  The page shows you the rule and what it thinks it's going to do.

                 

                You now need to restart Tomcat and your old URL <servername>/pls/apex should work for your users who have bookmarked your old apex apps.  It works for the new URL as well:  <servername>/apex

                 

                 

                I noticed you are also referencing port numbers in your sample url.  Take a look at this blog post below, specifically step 6 and 7 to learn how to redirect to 80, so you don't have to use a port.

                 

                Install Tomcat 7 on CentOS, RHEL, or Fedora : David Ghedini

                • 5. Re: Using Tomcat URL rewrite valve
                  partlycloudy

                  I tried these steps but they didn't work for me. Maybe I am missing something. Here is what I did

                   

                  1. My CATALINA_HOME is /home/myname/apache-tomcat-8.0.15

                  2. I copied urlrewritefilter-4.0.3.jar to $CATALINA_HOME/lib

                  3. Added the FILTER and FILTER-MAPPING sections to $CATALINA_HOME/webapps/ROOT/WEB-INF/web.xml right before the closing web-app tag

                  4. Created a new urlrewrite.xml file in $CATALINA_HOME/webapps/ROOT/WEB-INF/urlrewrite.xml with the XML fragment

                  5. Started Tomcat

                  6. http://server:port/pls/apex - Got a HTTP 404

                  7. http://server:port/rewrite-status - Got a HTTP 404

                   

                  What am I missing? Why is this so difficult?!

                   

                  Thanks

                   

                  Edit: OK I see that the status page is available only from the localhost but there is a filter parameter to change this behavior

                   

                  <init-param>

                          <param-name>statusEnabledOnHosts</param-name>

                          <param-value>*</param-value>

                  </init-param>

                   

                  I added this fragment in the FILTER section of the web.xml file and restarted Tomcat and now the status page works and shows the 1 rule in the urlrewrite.xml file.

                   

                  To my surprise, even the rewrite now works!  Not sure how the two are related but it works now.

                   

                  Thanks for your help!

                  • 6. Re: Using Tomcat URL rewrite valve
                    partlycloudy

                    Just to complete the loop. I was able to get the built-in Tomcat RewriteValve working as well. Just needed to put the rewrite.config file in the right location. See Tomcat 8.0 Rewrite Valve - Stack Overflow for details