【问题标题】:Using IIS URL Rewite to get rid of a subfolder name in my URL使用 IIS URL 重写删除我的 URL 中的子文件夹名称
【发布时间】:2020-06-16 05:14:37
【问题描述】:

我当前的网址如下:http://www.example.com/files/maps.html

我希望它看起来像:http://www.example.com/maps.html

基本上,我只是想去掉 URL 的“/files/”部分。我正在使用 IIS URL Rewrite 模块,但不熟悉它,也不熟悉 reg 表达式。

【问题讨论】:

    标签: regex iis url-rewriting url-rewrite-module


    【解决方案1】:

    您可以尝试使用以下规则:

    <rewrite>
            <rules>
                <clear />
    
                <rule name="Removefoldername" stopProcessing="true">
                    <match url="^abc$|^abc/page1.html$" />
                    <conditions>
                    </conditions>
                    <action type="Redirect" url="page1.html" />
                </rule>
                <rule name="RewriteToFile">
                    <match url="^(?!abc/)page1.html" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="abc/page1.html" />
                </rule>
            </rules>
    
        </rewrite>
    

    【讨论】:

    • 试过了,但似乎干扰了我的其他规则。我所拥有的:` `
    • 续:&lt;rule name="Redirecting .html ext" stopProcessing="true"&gt; &lt;match url="^(.*).html"/&gt; &lt;conditions logicalGrouping="MatchAny"&gt; &lt;add input="{URL}" pattern="(.*).html"/&gt; &lt;/conditions&gt; &lt;action type="Redirect" url="{R:1}"/&gt; &lt;/rule&gt;
    • @CancerPatient555 在我看来,不可能同时使用这两个规则。它会相互冲突。 other.如果您只想删除文件夹名称,则可以将此规则放在第一个位置&lt;rule name="Removefoldername" enabled="true" stopProcessing="true"&gt; &lt;match url="^abc$|^abc/page1$" /&gt; &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false" /&gt; &lt;action type="Redirect" url="page1.html" /&gt; &lt;/rule&gt;
    猜你喜欢
    • 2020-07-05
    • 2023-04-03
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 2023-03-09
    • 2013-11-08
    • 2014-04-22
    相关资源
    最近更新 更多