73

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.

Peter Hahndorf
  • 10,767
  • 4
  • 42
  • 58
xander
  • 1,427
  • 2
  • 16
  • 26

4 Answers4

140

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.

Nick Kovalsky
  • 5,378
  • 2
  • 23
  • 50
Peter Hahndorf
  • 10,767
  • 4
  • 42
  • 58
  • 49
    For me `fileExtension=".*"` didn't work, but `fileExtension="."` worked. – rustyx Mar 04 '15 at 10:58
  • 8
    This answer helped me to setup iOS Universal link apple-app-site-association file to be properly served by my website. Thanks a ton! – Nikhil Mathew Oct 14 '15 at 16:30
  • @NikhilMathew what mime type did you use to server your apple-app-site-association file? The above works for me to see the file but I'm not sure what mime type apple is expecting. I know it is application/pkcs7-mime if your file is encrypted, but supposedly you don't need to do that anymore so I am not sure what type to use for my non-encrypted file. – lehn0058 Oct 21 '15 at 21:12
  • 2
    Nevermind, I see that using application/json works :) – lehn0058 Oct 21 '15 at 21:25
  • `fileExtension="."` is what worked for me as well. h/t @RustyX – crthompson Nov 28 '16 at 18:31
  • Great answer. This didn't work on IIS5 (I'm working on migrating legacy apps and hit one!); but for that @RBT's solution worked (only using file extension `.`. instead of `.*`, as per other comments on here). – JohnLBevan Sep 12 '17 at 11:15
  • This answer helped me set up Let's Encrypt SSL on Godaddy Plesk Windows Shared Hosting. – JaYdipD Jul 15 '18 at 09:38
  • This `` makes IIS on latest Windows server throw an error "This is not well-formed XML". It doesn't like the space in `xml" />`. – Mike Makarov Jul 23 '18 at 00:05
  • @MikeMakarov you have to be more specific on what is the "latest Windows server" you refer to (1709 or Server 2019?). – Lex Li Sep 16 '18 at 03:45
  • @LexLi Server 2016, 1607 – Mike Makarov Sep 17 '18 at 17:43
  • For apple-app-site-association better use mimeType "application/json" , according to https://gist.github.com/andrewrohn/774185e4e15ddcc14f0a1e3c66c943e3 – Yair Zamir Aug 14 '19 at 08:17
  • Mime type should be "text/html" to avoid strict xml parsing errors – Shadi Alnamrouti Dec 05 '19 at 07:12
  • Thanks, web.config solution worked for me, for apple-app-site-association file i used MIME type as "application/json" – Rishabh Tailor Jun 01 '21 at 05:45
19

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.

MattBianco
  • 1,501
  • 2
  • 20
  • 30
  • 3
    you can have . in the start of a directory in windows just create a directory called `.well-known.` (explorer will remove the last dot and you will be left with `.well-known`) – Peter Jan 26 '16 at 15:28
  • 3
    The "Mime Types" section in IIS 7+ will allow you to do this as well. Right click, add an extension `.` (just a dot) with the mime type `text/plain` (for acme-challenge) or `text/xml` (for xml). – crthompson Nov 28 '16 at 18:30
  • thanks! this was my exact use case and need. you're a champ! – user319862 Aug 01 '20 at 19:14
13

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.

RBT
  • 24,161
  • 21
  • 159
  • 240
  • 8
    Quoting RustyX: "For me fileExtension=".*" didn't work, but fileExtension="." worked." – Ahmet Noyan Kızıltan Jun 01 '17 at 02:35
  • ok. Given the number of upvotes on @RustyX's comment I'm sure this is the case which you've observed. One of intentions of my post was also to make the readers aware on how to achieve this change through IIS manager UI instead of playing with config files directly. – RBT Jun 01 '17 at 02:41
  • This is really counterintuitively! But, this is working! – S.H. Apr 06 '22 at 09:55
  • IMO this is the safest way to do the change. In our case IIS was being used to update agents, but wasn't working for Linux. I added definitions for '.' and '.*' but got an 'internal server error' when I tried to download the file without the extension. Turned out the Sophos update site had '.*' already defined as 'Sophos/updates', so I removed my definition. All is well now: the addition of '.' definition was what fixed it ultimately. – Philip Kearns Jun 07 '22 at 11:34
0

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>
Hosam Rehani
  • 490
  • 6
  • 10