【问题标题】:URL friendly ASP Classic and Isapi RewriteURL 友好的 ASP Classic 和 Isapi 重写
【发布时间】:2019-09-05 16:37:31
【问题描述】:

关键是,我可以访问地址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

代码:

平均售价

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

【问题讨论】:

  • Server.Transfer url?
  • 我研究的@Lankymart在这种情况下不起作用
  • 我不明白你的友好网址是如何工作的。我看不出modulo 来自哪里,idtitulo 是查询字符串变量的名称,而不是值。 dominio.com/artigo/123/teste 将对应于 dominio.com/default.asp?link=artigo&amp;id=123&amp;titulo=teste
  • @John 准确。您引用的表格已经与我在问题中输入的代码一起使用。但我也想反过来工作。

标签: iis url-rewriting asp-classic web-config plesk


【解决方案1】:

您可以使用以下 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>

默认页面代码:

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

【讨论】:

  • 它对我不起作用,正常访问但仍然是原始链接
  • 您要更改站点 URL 还是页面内容?你能再详细解释一下你的要求吗?
  • 我只想更改网址。今天我的应用程序打开如下:www.domain.com/default.asp?link=test&id=123&title=title%20test。我想将此 URL 更改为 www.domain.com/test/123/title-test。
  • 所以用www.domain.com/default.asp?link=test&amp;id=123&amp;title=title%20test打开并显示www.domain.com/test/123/title-test
  • 我正在检查。由于 js、css 等依赖,我可能不得不对应用程序进行一些调整,但看起来它会起作用。
【解决方案2】:

我认为您所追求的是将“不友好”网址重定向到“友好”网址的规则 - 即,如果您将不友好的网址粘贴到浏览器地址栏中,那么当您的页面出现时,它会变为友好网址在屏幕中。 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 文件中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多