次の URL 書き換え構成があります。
web.xml :
<!--URL_REWRITE FILTER-->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- sets up log level (will be logged to context log)
can be: slf4j, TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL,
sysout:{level} (ie, sysout:DEBUG)
if you are having trouble using normal levels use sysout:DEBUG
(default WARN) -->
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
<!-- you can disable status page if desired
can be: true, false (default true) -->
<init-param>
<param-name>statusEnabled</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
urlrewrite.xml :
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<!--http://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html-->
<urlrewrite>
<rule>
<name>Home</name>
<from>^/$</from>
<to>/index.html</to>
</rule>
<rule>
<name>Api Versioning</name>
<note>The plan is to keep api versioning logic here (i.e. fallback and old version support), so that developer
doesn't have to worry
</note>
<from>^/v1/(.*)$</from>
<to last="true">/api/$1</to>
</rule>
<rule>
<name>Block Direct API access</name>
<from>^/api/(.*)$</from>
<to>/bla/$1</to>
</rule>
</urlrewrite>
にアクセスしようとするとhttp://localhost:8080/v1/ping
、 が表示されますProblem accessing /bla/ping. Reason:Not Found
。
ログは次のとおりです。
2016-12-15 01:31:41.553:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
2016-12-15 01:31:41.554:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for status path on /v1/ping
2016-12-15 01:31:41.556:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /v1/ping
2016-12-15 01:31:41.557:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Home (rule 0) run called with /v1/ping
2016-12-15 01:31:41.558:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Api Versioning (rule 1) run called with /v1/ping
2016-12-15 01:31:41.558:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: matched "from"
2016-12-15 01:31:41.561:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: found 1
2016-12-15 01:31:41.561:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: replaced sb is /api/ping
2016-12-15 01:31:41.566:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleExecutionOutput DEBUG: needs to be forwarded to /api/ping
2016-12-15 01:31:41.566:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: rule is last
2016-12-15 01:31:41.568:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for status path on /api/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /api/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Home (rule 0) run called with /api/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Api Versioning (rule 1) run called with /api/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Block Direct API access (rule 2) run called with /api/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: matched "from"
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: found 1
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.substitution.MatcherReplacer DEBUG: replaced sb is /bla/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleExecutionOutput DEBUG: needs to be forwarded to /bla/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.utils.ServerNameMatcher DEBUG: looking for hostname match on current server name localhost
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriteFilter DEBUG: checking for status path on /bla/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing request for /bla/ping
2016-12-15 01:31:41.569:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Home (rule 0) run called with /bla/ping
2016-12-15 01:31:41.570:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Api Versioning (rule 1) run called with /bla/ping
2016-12-15 01:31:41.570:INFO:/:qtp1686100174-51: org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: Block Direct API access (rule 2) run called with /bla/ping
マークされたルールで停止するように URL 書き換えを行う方法last
。