IIS 重写规则 - 如何在浏览器中打开网站时省略网站名称'index'文本



我正在为网站的索引.php页面使用以下IIS重写规则。

<rule name="INDEX">
<match url="^(.*)index$" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
<conditions logicalGrouping="MatchAll">  
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />  
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(user/inc|user/img)" ignoreCase="false" negate="true" />
</conditions> 
</rule>

当我访问 www.sitename.com 时,它会像 www.sitename.com/index 一样在网站末尾添加索引。

我想这样做,如果我写 www.websitename.com 或 www.websitename.com/index,它应该只显示 www.sitename.com。请让我知道我该怎么做。

最后,

我想出了我的问题的解决方案。

在编写任何规则之前,请在 web.config 文件中添加以下代码。还要根据网站的路径更改索引.php页面的路径。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument enabled="true">
            <files>
                <remove value="user/index.php" />
                <add value="user/index.php" />
            </files>
        </defaultDocument>
        <rewrite>  
            <rules>
                <rule name="INDEX">
                    <match url="^(.*)index$" />
                    <action type="Rewrite" url="user/index.php" appendQueryString="true" />
                    <conditions logicalGrouping="MatchAll">  
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />  
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_URI}" pattern="^/(user/inc|user/img)" ignoreCase="false" negate="true" />
                    </conditions> 
                </rule>
            </rules>  
        </rewrite>
    </system.webServer>
</configuration>

最新更新