Match any url to a servlet

55 views
Skip to first unread message

Robert Artenie

unread,
Aug 8, 2015, 5:05:15 AM8/8/15
to UrlRewrite

Ive been trying something like this:


^/([a-z0-9-/]+)$
w?page=$1 

Trying to redirect all pages after mywebsite.com/, after the last / to a servlet, but ends up in endless error loop. Also posted a thread in stack overflow, here: http://stackoverflow.com/questions/31677049/tuckey-url-rewrite-filter-rules

Is there any way to match ANY url, even if it doesnt exist?

Ondřej Světlík

unread,
Aug 10, 2015, 5:53:04 AM8/10/15
to urlre...@googlegroups.com
Dne 7.8.2015 v 16:55 Robert Artenie napsal(a):
Hi there,

I think I've already answered such question here :-)



Copy:

Hello,

I guess you have your forward request also filtered and so on.


request -> urlrewritefilter -> forward -> urlrewritefilter -> forward...

There are a few solutions:

1. forward to uri that is not filtered:

urlrewrite.xml
<rule>
<from>^/mypath</from>
<...>do whatever you want to</...>
<to>/internal/mypath</to>
</rule>

2. setup urlrewrite to handle only requests and not forwards:
web.xml:
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

3. set some request scope attribute to skip further processing:
urlrewrite.xml:
<rule>
<condition
type="attribute"
name="alreadyFiltered"
operator="notequal
>alreadyFiltered</condition>
<from>^/mypath</from>
<...>do whatever you want to</...>
<set name="alreadyFiltered">alreadyFiltered</set>
</rule>

I use number 2, because I never needed to filter forwarded requests.
Every <to type="forward" /> (type="forward" is default) element creates
one and it always gets messy .

I hope this helps.

With regards

Ondrej

Reply all
Reply to author
Forward
0 new messages