1

次のようなワードプレスのパーマリンクを有効にするにはどうすればよいですか

http://www.mysite.co.uk/blog/sample-post/

Quercus と Wordpress で Tomcat 7 を実行しています。現時点では、404 エラーが発生します。

4

1 に答える 1

1

Tuckey を次のようにセットアップします。

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>

次のクラスを lib ディレクトリにコピーします。

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();
        }
}
于 2013-07-01T22:58:24.500 に答える