问题
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