简体   繁体   English

tomcat重写,配置读取但不工作

[英]tomcat rewrite, config read but not working

I'm trying to have the URL localhost/article/article-title to "execute" the URL localhost/getArticle?article-title. 我正在尝试使用URL localhost / article / article-title来“执行”URL localhost / getArticle?article-title。

I think I've configured my valve right, because I see this in the log : 我想我已经配置了我的阀门,因为我在日志中看到了这个:

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

I've actived it on the server.xml and in the context.xml. 我已经在server.xml和context.xml中激活了它。 The file rewrite.config is read because in the log, you can see this : 读取文件rewrite.config是因为在日志中,您可以看到以下内容:

Add rule with pattern ^article/(.*) and substitution getArticle?$1

This is the content of my rewrite.config : 这是我的rewrite.config的内容:

#To make it work, active the Rewrite Valve is ../META-INF/context.xml 
RewriteRule ^article/(.*) getArticle?$1 [L]

But when I go to http://localhost/article/article-title , I got this in the log : 但是当我去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

How can I be sure the Rewriting is activated ? 我怎样才能确定重写是否已激活?

Thanks for your time. 谢谢你的时间。

The path to be matches in the RewriteRule is relative to the current container. RewriteRule中要匹配的路径是相对于当前容器的。 So the RewriteRule should read: 所以RewriteRule应该是:

RewriteRule ^/article-(.*) getArticle?$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM