如何排除我的管理目录在其网址中隐藏 .html

XuDong Peng-MSFT 10,181 信誉分 Microsoft 供应商
2024-03-28T06:26:59.3833333+00:00

我用它来删除我网站上网址中的 .html:

<rewrite>  
        <rules>  
            <remove name="Redirecting .html ext" />  
            <remove name="Hide .html ext" />  
            <rule name="Hide .html ext" enabled="true">  
                <match url="^(.*)" ignoreCase="true" />  
                <conditions>  
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />  
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />  
                    <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />  
                </conditions>  
                <serverVariables />  
                <action type="Rewrite" url="{R:0}.html" />  
            </rule>  
            <rule name="Redirecting .html ext" enabled="true" stopProcessing="true">  
                <match url="^(.*).html" />  
                <conditions logicalGrouping="MatchAny">  
                    <add input="{URL}" pattern="^(.*)\.html$" />  
                </conditions>  
                <serverVariables />  
                <action type="Redirect" url="{R:1}" />  
            </rule>  
        </rules>  
    </rewrite>

我需要省略我的 --admin 目录及其所有子目录,以免删除 html

从类似的问题中尝试了一些事情,但没有运气。

我想排除 www.website.com/--admin 删除它的任何 html 扩展名。

我使用 www.website.com/--admin/page.html?id=new 和类似的,如果 html 被删除,那么一切都会失败。

感谢您的任何建议。

Note: 该问题整理于:How to exclude my admin directories from hiding .html in its urls

Internet Information Services
0 个注释 无注释
{count} 票

接受的答案
  1. Zhi Lv - MSFT 32,036 信誉分 Microsoft 供应商
    2024-03-28T07:47:54.84+00:00

    你好,

    根据你的描述,我认为你想在URL中隐藏.html,但不想在包含admin目录及其所有子目录的URL中隐藏.html,因为这会出错。我有一个方法需要对名为“Redirecting.html ext”的重写规则进行一些修改。 在匹配的URL中,使用正则表达式排除特定字符串“admin”

    <match url="^(.*).html" /> is changed to <match url="^(?!admin)(.*).html" / >
    

    这对我有用,你可以试试。


    如果答案是正确的解决方案,请单击“接受答案”并请投赞成票。如果您对此答案有其他疑问,请点击“评论”。

    注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知。

    最好的问候

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助