具有Mime映射的无扩展URL

时间:2011-12-03 13:19:44

标签: iis iis-7 mime-types

我正在尝试在新主机上恢复旧网站。它最初使用MovebleType,因此所有模板文件都是无扩展名的HTML文件。我试图让IIS7为没有扩展名的文件提供所有文件请求text/html,但没有太多运气。 IIS论坛上的帖子提出了一个重写规则,对我来说没有意义,似乎没有用。我还尝试了几个mimeMaps,所有这些都导致了HTTP错误。到目前为止,这是我的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <rewrite>
            <rules>
                <rule name="Extensionless" stopProcessing="true">
                    <match url="^[\w_/]+$" />
                    <action type="Rewrite" url="{R:0}.htm" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

.htaccess等价物更重要 - DefaultType php5-cgi

这应该可以在IIS7中实现吗?

2 个答案:

答案 0 :(得分:8)

我实际上需要.

的MimeMap
   <staticContent>
       <mimeMap fileExtension="." mimeType="text/html" />
   </staticContent>

答案 1 :(得分:3)

对于IIS 10,我发现在web.config文件中,IIS不喜欢xml标记,只有在你的XML文件根标记是配置时才有效,这使得我当前的web.config文件看起来像:

<configuration>
 <system.webServer>
    <staticContent>
        <mimeMap fileExtension="." mimeType="text/html" />
    </staticContent>
 </system.webServer>
</configuration>
相关问题