我试图获取该网址 localhost / article / article-title to"执行" URL 本地主机/ getArticle?文章标题。
我认为我已正确配置了我的阀门,因为我在日志中看到了这一点:
03-Apr-2016 01:11:38.206 FINE [Catalina-startStop-1] org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read configuration from /usr/local/apache-tomcat-8.0.33/conf/Catalina/localhost/rewrite.config
03-Apr-2016 01:11:38.208 FINE [Catalina-startStop-1] org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with pattern ^article/(.*) and substitution getArticle?$1
03-Apr-2016 01:11:38.775 FINE [localhost-startStop-1] org.apache.catalina.valves.rewrite.RewriteValve.startInternal Read configuration from: /WEB-INF/rewrite.config
03-Apr-2016 01:11:38.775 FINE [localhost-startStop-1] org.apache.catalina.valves.rewrite.RewriteValve.parse Add rule with pattern ^article/(.*) and substitution getArticle?$1
我已经在server.xml和context.xml中激活了它。读取文件rewrite.config是因为在日志中,您可以看到:
Add rule with pattern ^article/(.*) and substitution getArticle?$1
这是我的rewrite.config的内容:
#To make it work, active the Rewrite Valve is ../META-INF/context.xml
RewriteRule ^article/(.*) getArticle?$1 [L]
但是当我去http://localhost/article/article-title时,我在日志中得到了这个:
27.0.0.1 - - [03/Apr/2016:01:12:01 +0200] "GET /article/article-title HTTP/1.1" 404 1036
如何确定重写已激活?
感谢您的时间。
答案 0 :(得分:0)
RewriteRule中要匹配的路径是相对于当前容器的。所以RewriteRule应该是:
RewriteRule ^/article-(.*) getArticle?$1 [L]