Question

I'm trying out Tuckey's URLRewriter.

I declared one simple rule, as follows:

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

I would expect requests like myapp.com/user/29 to be mapped to 'myapp.com/user.do?id=29'. This works fine and the request arrives on the backed. When viewing the response on GUI however, this is how Firebug complains:

enter image description here

As you can see, between /roqket and /resources there is now a /user. I have no idea how that ended up there. If I remove the <rule> it goes back to the normal, working resource requests.

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

Was it helpful?

Solution

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

Something like this:

<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 should be declare before the one you define for the user. These rules will match before the one that apply to the filter and your problem should be solved.

Edit.

Regarding your comment: That user which can be seen in the print screen is added somehow by the filter.

I think that is not correct, I mean, the filter is not the one that is adding "user" to the filter. I think the problem is how you are importing your resources.

Probably, you are doing something like this:

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

In this example, see how the relative URI doesn't not content your application context and starts with no slash. When you use a URL like that the browser is going to look for the resource in a path relative to actual path. If you have in your browser http://localhost:8080/roqlet/user the result will be http://localhost:8080/roqket/user/theResource (assuming 'roqket' is your app context).

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, that you indicate the context, the URI will be built relative to it and not to the actual: http://localhost:8080/roqket/theResource

Take a look to this doc.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top