javaurl-rewritingtuckey-urlrewrite-filter

UrlRewriterFilter rule not working


I use Struts for my web application.

For rewriting URLs I use UrlRewriteFilter.

This is my urlrewrite.xml code:

<urlrewrite>
<rule>
    <from>^/job/([0-9]+)$</from>
    <to>/job.do?selAction=detail&amp;idx=$1</to>
</rule>
<rule>
    <from>^/jobs</from>
    <to>/job.do</to>
</rule>
<rule>
    <from>^/main</from>
    <to>/main.do</to>
</rule>
</urlrewrite>

First and second URI work well. But third one (^/main) is not working. When I change third URI from ^/main to ^/main/, it works but I don't know how (I guess it is related with URI depth). What should I do?


Solution

  • Try putting $ at the end of your 2nd and 3rd <from> tags, as suggested in the manual:

    <rule>
        <from>^/jobs$</from>
        <to>/job.do</to>
    </rule>
    <rule>
        <from>^/main$</from>
        <to>/main.do</to>
    </rule>