w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Wordpress Permalinks on Quercus + Tomcat

Setup Tuckey as follows:

urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
   "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">

<urlrewrite>
   <class-rule class="com.tomcatrewrite.TomcatRule" />
</urlrewrite>

Copy the following classes to the lib directory:

public class TomcatMatch extends RewriteMatch {

    /**
     * Do the actual rewrite. Request URI in the form "/node/3" would be
     * rewritten to "/index.php?q=node/3" and then forwarded.
     */
    public boolean execute(HttpServletRequest request, HttpServletResponse
response) throws ServletException,
            IOException {
        String queryString = request.getQueryString();
        // Do the rewrite

        StringBuilder newURI = new StringBuilder(512);

       
newURI.append("/index.php?q=").append(request.getRequestURI().substring(1));

        if (queryString != null) {

            newURI.append("&").append(request.getQueryString());
        }
        System.out.println("changes = " + newURI.toString());

        RequestDispatcher rd =
request.getRequestDispatcher(newURI.toString());
        rd.forward(request, response);
        return true;
    }
}



public class TomcatRule extends RewriteRule {
        private ServletContext sc;

        /**
         * Initialization method - saves the ServletContext object so that
         * it can be used later to determine the actual filesystem path
         * to a requested object.
         *
         * @param sc The ServletContext object.
         * @return true
         */
        public boolean init(ServletContext sc) {
                this.sc = sc;

                return true;
        }


        /**
         * Performs the actual testing to determine if the request URL is
to be rewritten.
         *
         * @param request The HttpServletRequest object.
         * @param response The HttpServletResponse object.
         * @return RewriteMatch object which is to perform the actual
rewrite.
         */
        public RewriteMatch matches(HttpServletRequest request,
HttpServletResponse response) {
                String virtualPath = request.getServletPath();


                if (virtualPath == null) return null;

                if (virtualPath.equals("/")) return null;

                if (virtualPath.equals("/favicon.ico")) return null;



                // No rewrite if real path cannot be obtained, or if
request URI points to a
                // physical file or directory

                String realPath = sc.getRealPath(virtualPath);

                System.out.println("Real Path:");
                if (realPath == null) return new TomcatMatch();


                File f = new File(realPath);



                if (f.isFile() || f.isDirectory() || f.isHidden()) {

                    return null;
                }

                // Return the RewriteMatch object
                return new TomcatMatch();
        }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.