Search code examples
javatomcatliferaytomcat7

UrlRewriteFilter regex rule not working as expected


I added some rules to urlrewrite.xml file, but it is not working as expected.

The rule <from>^/documents/.*RDC.*$</from>, should only redirect when the URL contains a uppercase "RDC", but is also redirecting for lowercase "rdc"

http://my-server/documents/test-RDC.pdf

I'm using Liferay 6.2, which has a tomcat server on version 7.

Can anyone help?

liferay-dir/tomcat/webapps/ROOT/WEB-INF/urlrewrite.xml

<?xml version="1.0"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN" "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">

<urlrewrite>
    <!-- Regras de redirecionamento por palavra-chave (Cenário 2) -->
    <rule>
        <from>^/documents/.*(?i)consulta.*$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=630&amp;menuOpen=true</to>
    </rule>

    <rule>        
        <from>^/documents/.*RDC.*$</from>        
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=310&amp;menuOpen=true</to>    
    </rule>

    <rule>        
        <from>^/documents/.*IN.*$</from>        
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=310&amp;menuOpen=true</to>    
    </rule>
   
    <rule>
        <from>^/documents/.*(?i)guia.*$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=644&amp;menuOpen=true</to>
    </rule>

    <!-- Regras de redirecionamento direto (Cenário 1) -->
    <rule>
        <from>^/legislacao(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/AutenticacaoAction.php?acao=acessarModuloCidadao</to>
    </rule>
    <rule>
        <from>^/propostas-regulatorias(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/AutenticacaoAction.php?acao=acessarModuloCidadao</to>
    </rule>
    <rule>
        <from>^/documents/.*$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/AutenticacaoAction.php?acao=acessarModuloCidadao</to>
    </rule>
    <rule>
        <from>^/consultas-publicas(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=630&amp;menuOpen=true</to>
    </rule>
    <rule>
        <from>^/editais-de-chamamento(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=630&amp;menuOpen=true</to>
    </rule>
    <rule>
        <from>^/tap(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=631&amp;menuOpen=true</to>
    </rule>
    <rule>
        <from>^/guias(#/.*)?$</from>
        <to type="permanent-redirect">https://anvisalegis.datalegis.net/action/ActionDatalegis.php?acao=categorias&amp;cod_modulo=644&amp;menuOpen=true</to>
    </rule>
</urlrewrite>

Solution

  • The <from> element supports a casesensitive boolean attribute which defaults to false.

    So, specify the attribute with a value of true for the desired behavior.

    Used these docs for reference

    <from casesensitive="true">^/documents/.*RDC.*$</from>