Search code examples
iisurl-rewritingasp-classicweb-configplesk

URL friendly ASP Classic and Isapi Rewrite


The point is, I can access an address dominio.com/modulo/id/titulo and it rewrites to dominio.com/default.asp?link=artigo&id=123&titulo=teste, but my question is whether I can do the reverse process, i.e. go to dominio.com/default.asp?link=artigo&id=123&titulo=teste and it changes to dominio.com/modulo/id/titulo.

Codes:

ASP

<!DOCTYPE html><html lang="pt-br"><head><meta charset="utf-8"/><title>Teste Isapi Rewrite</title></head><body><p>Teste!<br>link: <%=request("link")%><br>id: <%=request("id")%><br>teste: <%=request("teste")%><br></p></body></html>

WEB.CONFIG

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<system.webServer>
    <rewrite>
        <rules>
            <rule name="artigo" stopProcessing="true">
                <match url="^artigo/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9_-]+)?$" />
                <conditions> 
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
                </conditions>
                <action type="Rewrite" url="default.asp?link={R:0}&amp;id={R:1}&amp;teste={R:2}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

</configuration>

Solution

  • You could use below url rewrite rule:

     <rule name="reverse" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_URI}" pattern="default.asp" />
                        <add input="{QUERY_STRING}" pattern="link=(.*)\&amp;id=(.*)\&amp;titulo=(.*)" />
                    </conditions>
                    <action type="Redirect" url="http://{HTTP_HOST}/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
                </rule>
    
    
                <rule name="RewriteUserFriendlyURL1" enabled="true" stopProcessing="true">
                    <match url="^([^/]+)/([^/]+)/([^/]+)/?$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="default.asp?link={R:1}&amp;id={R:2}&amp;titulo={R:3}" appendQueryString="false" />
                </rule>
    

    default page code:

    <!DOCTYPE html><html lang="pt-br">
    <head>
    <meta charset="utf-8"/>
    <title>Teste Isapi Rewrite</title>
    </head>
    <body>
    <p>Teste!<br>link: <%=request("link")%><br>id: <%=request("id")%><br>titulo: <%=request("titulo")%><br></p>
    </body>
    </html>
    

    enter image description here