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}&id={R:1}&teste={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
2
Answers
You could use below url rewrite rule:
default page code:
What I think you’re after is a rule which redirects the “unfriendly” URL to the “friendly” one – ie if you paste the unfriendly one into your browser address bar then it changes to the friendly one when your page appears in the screen. Janvi Panchal has the right idea above. What you do is have a redirect rule and a rewrite rule as follows.
Note that the redirect rule comes first, so what’s happening is that the location is redirected to the friendly URL which is then rewritten as the unfriendly one.
Also note that I didn’t hand code this – I generated it with the URL rewrite wizard in IIS Manager. Click on the URL Rewrite icon, then Add Rule then User Friendly URL. Check the “Create corresponding redirect rule” before you click the OK button and this code will be generated and appended to your web.config file in the appropriate location