Iis URL友好的ASP经典和Isapi重写

Iis URL友好的ASP经典和Isapi重写,iis,url-rewriting,asp-classic,web-config,plesk,Iis,Url Rewriting,Asp Classic,Web Config,Plesk,关键是,我可以访问一个地址dominio.com/modulo/id/titulo,然后它被重写为dominio.com/default.asp?link=artigo&id=123&titulo=teste,但我的问题是我是否可以做相反的过程,也就是说,转到dominio.com/default.asp?link=artigo&id=123&titulo=teste,它将更改为dominio.com/modulo/id/titulo 代码: ASP <!DOCTYPE html>&

关键是,我可以访问一个地址
dominio.com/modulo/id/titulo
,然后它被重写为
dominio.com/default.asp?link=artigo&id=123&titulo=teste
,但我的问题是我是否可以做相反的过程,也就是说,转到
dominio.com/default.asp?link=artigo&id=123&titulo=teste
,它将更改为
dominio.com/modulo/id/titulo

代码:

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>
Teste-Isapi-RewriteTeste<链接:
id:
teste:

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>

您可以使用以下url重写规则:

 <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>


我认为您所追求的是一条规则,它将“不友好”URL重定向到“友好”URL,即如果您将不友好的URL粘贴到浏览器地址栏中,那么当您的页面出现在屏幕上时,它将变为友好的URL。Janvi Panchal的上述想法是正确的。您要做的是有一个重定向规则和一个重写规则,如下所示

<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
     <match url="^dominio\.com/default\.asp$" />
     <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^link=([^=&amp;]+)&amp;id=([^=&amp;]+)&amp;titulo=([^=&amp;]+)$" />
     </conditions>
     <action type="Redirect" url="dominio.com/default/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
     <match url="^dominio\.com/default/([^/]+)/([^/]+)/([^/]+)/?$" />
     <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     </conditions>
     <action type="Rewrite" url="dominio.com/default.asp?link={R:1}&amp;id={R:2}&amp;titulo={R:3}" />
 </rule>

请注意,重定向规则首先出现,因此发生的情况是位置被重定向到友好URL,然后被重写为不友好URL


还请注意,我并没有手工编写此代码-我是通过IIS管理器中的URL重写向导生成的。单击URL重写图标,然后添加规则,然后单击用户友好URL。在单击“确定”按钮之前,请选中“创建相应的重定向规则”,此代码将生成并附加到相应位置的web.config文件中

Server.Transfer url
?@Lankymart从我研究的内容中删除在这种情况下不起作用我不明白您的友好url是如何工作的。我看不出模从何而来,
id
titulo
是querystring变量的名称,而不是值
dominio.com/artigo/123/teste
将对应于
dominio.com/default.asp?link=artigo&id=123&titulo=teste
@John exact。你引用的表格已经与我在问题中输入的代码一致。但是我也希望反向工作。这对我不起作用,正常访问但仍然是原始链接。你想更改网站URL还是页面内容?你能再详细解释一下你的要求吗?我只想更改网址。今天,我的应用程序打开如下:www.domain.com/default.asp?link=test&id=123&title=title%20test。我想将此URL更改为www.domain.com/test/123/title-test.So,用
www.domain.com/default.asp?link=test&id=123&title=title%20test打开,并显示
www.domain.com/test/123/title-test
我正在检查。由于js、css等依赖关系,我可能不得不对应用程序进行一些调整,但它看起来会起作用。
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
     <match url="^dominio\.com/default\.asp$" />
     <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^link=([^=&amp;]+)&amp;id=([^=&amp;]+)&amp;titulo=([^=&amp;]+)$" />
     </conditions>
     <action type="Redirect" url="dominio.com/default/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
     <match url="^dominio\.com/default/([^/]+)/([^/]+)/([^/]+)/?$" />
     <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     </conditions>
     <action type="Rewrite" url="dominio.com/default.asp?link={R:1}&amp;id={R:2}&amp;titulo={R:3}" />
 </rule>