首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Quercus + Tomcat上的Wordpress Permalink

Quercus + Tomcat上的Wordpress Permalink
EN

Stack Overflow用户
提问于 2013-06-30 00:07:31
回答 1查看 635关注 0票数 1

如何启用wordpress permalinks,如

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

我和Quercus和Wordpress一起运行Tomcat 7。目前,我只收到404个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-01 22:58:24

设置图基如下:

urlrewrite.xml:

代码语言:javascript
复制
<?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目录:

代码语言:javascript
复制
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();
        }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17385853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档