Quercus + Tomcat 上的 Wordpress 永久链接 [英] Wordpress Permalinks on Quercus + Tomcat

查看:29
本文介绍了Quercus + Tomcat 上的 Wordpress 永久链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启用 wordpress 永久链接,例如

How do I enable wordpress permalinks such as

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

我正在使用 Quercus 和 Wordpress 运行 Tomcat 7.目前我只收到 404 错误.

I'm running Tomcat 7 with Quercus and Wordpress. At the moment I just get 404 errors.

推荐答案

Setup Tuckey 如下:

Setup Tuckey as follows:

urlrewrite.xml:

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 目录:

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();
        }
}

这篇关于Quercus + Tomcat 上的 Wordpress 永久链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆