Extensionless URLs with Mime Mapping

与世无争的帅哥 提交于 2019-12-12 13:24:36

问题


I'm trying to resurrect an old site on a new host. It originally used MovebleType, so all of the template files are extensionless HTML files. I'm trying to get IIS7 to serve all requests to files without an extension as text/html but not having much luck. A post on the IIS forum suggested a rewrite rule, which to me doesn't make sense and doesn't seem to work. I've also tried several mimeMaps, all of which resulted in HTTP errors. This is my web.config so far:

<?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>

The .htaccess equivalent is more to the point - DefaultType php5-cgi

This should be possible in IIS7 shouldn't it?


回答1:


I actually needed a MimeMap for .

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



回答2:


For IIS 10, I've found that in web.config files, IIS doesn't like the xml tag, and only works if your XML files root tag is configuration, making my current web.config file look like:

<configuration>
 <system.webServer>
    <staticContent>
        <mimeMap fileExtension="." mimeType="text/html" />
    </staticContent>
 </system.webServer>
</configuration>


来源:https://stackoverflow.com/questions/8367920/extensionless-urls-with-mime-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!