Tuckey Urlrewriter modifies URL requests for JS and CSS resources

I am trying to download a Tuckey url.

I declared one simple rule:

<rule> <from>/user/([0-9]+)$</from> <to>/user.do?id=$1</to> </rule> 

I expect requests like myapp.com/user/29 to be mapped to 'myapp.com/user.do?id=29'. This works great, and the request comes in for support. However, when viewing the response on the GUI, Firebug complains:

enter image description here

As you can see, between /roqket and /resources / user now exists. I have no idea how it ended. If I delete the <rule> , it will return to the normal working resource requests.

Could you help me? What am I missing? Thanks!

+4
source share
2 answers

You need to define other filters for js, style and img.

Something like that:

 <rule> <from>/img/**</from> <to>/img/$1</to> </rule> <rule> <from>/js/**</from> <to>/js/$1</to> </rule> <rule> <from>/style/**</from> <to>/style/$1</to> </rule> 

These filters must be declared before the one you define for the user. These rules will correspond to those that apply to the filter, and your problem should be resolved.

Edit

Regarding your comment: this user, which can be seen on the print screen, is somehow added by the filter.

I think this is wrong, I mean that the filter is not the one that adds β€œuser” to the filter. I think the problem is how you import your resources.

Perhaps you are doing something like this:

 <script type="text/javascript" language="javascript" src="resources/js/lang.js"></script> 

In this example, see how a relative URI does not suit your application context and starts without a slash. When you use such a URL, the browser will look for the resource in the path relative to the actual path. If you have http://localhost:8080/roqlet/user in your browser, the result will be http://localhost:8080/roqket/user/theResource (assuming "roqket" is the context of your application).

So you should do this:

 <c:set var="ctx" value="${pageContext.request.contextPath}"/> <script type="text/javascript" language="javascript" src="${ctx}/resources/js/lang.js"></script> 

Now, when you specify the context, the URI will be created relative to it, and not the actual one: http://localhost:8080/roqket/theResource

Look at the doc .

+1
source
 <rule> <condition type="request-uri" operator="notequal">\.(images|gif|jpeg|png|css|js|pdf|doc|ico|jsp|jpg)$</condition> <from>............ 

this is a way to stop the request from the tuskey url rewrite filter

0
source

Source: https://habr.com/ru/post/1444369/


All Articles