xander
xander

Reputation: 1447

IIS: How to serve a file without extension?

I am using IIS 8 on Windows 8.1. I have an XML file an I need to have it accessed through (servername)/(path)

(path) is predefined by someone else and does not contain an extension. I tried the simple solution of removing the .xml file the file name, but IIS returns HTTP Error 404.3 - Not Found

In the "Physical Path" returned with the error is the correct file path, which when I copy-paste to Run opens the correct file.

Please let me know if this is possible.

Upvotes: 74

Views: 85411

Answers (5)

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

Below worked for me with IIS 10 and windows 11.

<rewrite>
<rules>
    <rule name="Hide .html ext">
        <match ignoreCase="true" url="^(.*)"/>
        <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>
        <action type="Rewrite" url="{R:0}.html"/>
    </rule>
    <rule name="Redirecting .html ext" stopProcessing="true">
        <match url="^(.*).html"/>
        <conditions logicalGrouping="MatchAny">
            <add input="{URL}" pattern="(.*).html"/>
        </conditions>
        <action type="Redirect" url="{R:1}"/>
    </rule>
</rules>

Upvotes: 0

RBT
RBT

Reputation: 25887

Changing the configurations by hand can be error-prone. So Internet Information Server (IIS) console GUI provides an easier and error-free way to update the MIME-types. Please follow the steps below:

  1. Open IIS

  2. Expand your website's node in the left navigation pane.

  3. Select your application or virtual directory.

  4. Double-click MIME Types feature under IIS section in the right pane:

    enter image description here

  5. Click Add.. link in Actions pane. Set-up the mime type to support all files without extension. Then click OK :

    enter image description here

Behind the scene, these steps make changes to web.config file of your application or virtual directory (under your website) as suggested in PeterHahndorf's post.

Note: The screenshots shown in the steps above have been taken from Windows 10 machine having IIS v10.

Upvotes: 14

Hosam Rehani
Hosam Rehani

Reputation: 516

for me, I want only to serve one file so what I did is just add a simple rewrite as the other methods posted here didn't work for some reasons

  <system.webServer>
      <rewrite>
          <rules>
              <rule name="apple-app-site-association" patternSyntax="ExactMatch">
                  <match url="apple-app-site-association" />
                  <action type="Rewrite" url="/apple-app-site-association.txt" />
              </rule>
          </rules>
      </rewrite>
  </system.webServer>

Upvotes: 0

Peter Hahndorf
Peter Hahndorf

Reputation: 11222

Assuming (path) is a physical directory on your machine, create a new web.config file in that directory with the following content:

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
     <system.webServer>
         <staticContent>
             <mimeMap fileExtension="." mimeType="text/xml" />
         </staticContent>
     </system.webServer>
 </configuration>

You are telling IIS that for this directory only, any file without an otherwise defined extension (in MIME types) should be considered an xml file. Other file types in the same path should still work.

If you have the Windows feature IIS Management Scripts and Tools installed, you can use PowerShell to create such a web.config file:

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site/.well-known'  -filter "system.webServer/staticContent" -name "." -value @{fileExtension='.';mimeType='text/xml'}

in this example Default Web Site is the name of the web site and .well-known is a directory under that site.

Upvotes: 149

MattBianco
MattBianco

Reputation: 1531

It can be done in IIS 6 as well / without using web.config, but instead using the management GUI to add a MIME type for extension . here:

enter image description here

For instance, to serve a .well-known/acme-challenge token, create a virtual directory called .well-known, and have it take its contents from a physical directory (that cannot have names with leading dots in windows). Then add a text/plain MIME type for the extension . in this directory, and you can manually acquire new letsencrypt certificates for a domain that is currently served by an old IIS.

Upvotes: 19

Related Questions