如何启用 wordpress 永久链接,例如
我正在使用 Quercus 和 Wordpress 运行 Tomcat 7。目前我只收到 404 错误。
如何启用 wordpress 永久链接,例如
我正在使用 Quercus 和 Wordpress 运行 Tomcat 7。目前我只收到 404 错误。
设置 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();
}
}