【问题标题】:IIS URL Rewrite multiple parametersIIS URL 重写多个参数
【发布时间】:2017-03-20 16:49:08
【问题描述】:

我真的对 URL 重写接口感到困惑。我不明白我需要做什么。 我有一个网址:

www.example.com/diretory/subdirectory/index.html?param1=1&param2=2&param3=2&param4=7

我想将此网址隐藏在<a>-href 标记中,该标记显示“示例标记”。 当请求 url 时,它应该将其重写为

www.example.com/program/location/year/vacancie

我已经试过了:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="\?([^/]+)&amp;([^/]+)&amp;([^/]+)&amp;([^/]+)" />
                <action type="Rewrite" url="www.example.com/program/location/year/vacancie" logRewrittenUrl="true" />
                <conditions>
                </conditions>
            </rule>
        </rules>
    </rewrite>
</system.webServer>

在 URL 重写接口中,Test Pattern 表示它正在工作并获取:

?param1=1&param2=2&param3=2&param4=7
param1=1
param2=2
param3=2
param4=7

我也检查了日志 url 重写,但在我的日志中没有显示。

2017-03-20 16:29:24 192.168.253.146 GET /diretory/subdirectory/index.html param1=1&param2=2&param3=2&param4=7 88 - 192.168.253.146 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 304 0 0 4

ps:网址无效,仅用于说明目的。

【问题讨论】:

    标签: url iis url-rewriting


    【解决方案1】:

    匹配 URL 仅匹配 URL,不考虑查询字符串。您需要为此添加一个条件。你也想重写这个(这样服务器在内部执行新的 URL)还是重定向(这样服务器将请求浏览器转到新的 URL 和地址栏中的 URL 更改)。如果你想重写你不应该再次添加域,如果你想重定向添加 http:// 。假设重写是您想要使用的以下规则:

     <rule name="ProgramRewrite" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="(.*)" />
                <action type="Rewrite" url="/program/location/year/vacancie" logRewrittenUrl="true" />
                <conditions>
                        <add input="{QUERY_STRING}" pattern="([^/]+)&amp;([^/]+)&amp;([^/]+)&amp;([^/]+)" />
                </conditions>
            </rule>
    

    【讨论】:

    • 这就是答案。我的 url 重写有问题。我希望用户可以打开www.example.com/program/location/year/vacancie 并打开www.example.com/diretory/subdirectory/index.html?param1=1&amp;param2=2&amp;param3=2&amp;param4=7,但仍将www.example.com/program/location/year/vacancie 在浏览器中显示为url。这可能吗?
    • 我明白了,所以您想匹配 /program/location/year/vacancie,然后在内部将其发送到 /diretory/subdirectory/index.html?param1=1&pa‌​ram2=2&param3=2&para‌​m4 =7 ?
    • 如果这是你想要的,那实际上要容易得多:
    • 好的,这是正确地重定向我。另外:我需要用静态href引用我的脚本吗,因为url,它找不到它们。
    • 我如何读取重写后的 url 上的 Url 参数?因为我的脚本中需要它们。我需要使用 param1/2/3/4 在页面上获取正确的数据。
    猜你喜欢
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 2011-06-21
    • 2017-02-03
    • 2016-07-29
    相关资源
    最近更新 更多