Created
September 17, 2020 17:28
-
-
Save icavalheiro/a96f20ff8071535806b2628252f2a837 to your computer and use it in GitHub Desktop.
Web.config for static file serving with IIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!-- This is a web.config for static file serving in a windows ISS web server | |
Created by Ivan S Cavalheiro [[email protected]] --> | |
<configuration> | |
<system.webServer> | |
<!-- custom error pages --> | |
<httpErrors errorMode="Custom"> | |
<remove statusCode="500" subStatusCode="-1" /> | |
<remove statusCode="404" subStatusCode="-1" /> | |
<error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" /> | |
<error statusCode="500" prefixLanguageFilePath="" path="/500.html" responseMode="ExecuteURL" /> | |
<error statusCode="500" subStatusCode="100" path="/500.html" responseMode="ExecuteURL" /> | |
</httpErrors> | |
<rewrite> | |
<rules> | |
<!-- force https --> | |
<!-- <rule name="Redirect to HTTPS" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{REMOTE_PORT}" pattern=".*" /> | |
<add input="{HTTPS}" pattern="^OFF$" /> | |
</conditions> | |
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> | |
</rule> --> | |
<!-- remove file extensions from html files (make it beauty) --> | |
<rule name="RewriteHtml"> | |
<match url="^(.*)$" /> | |
<conditions logicalGrouping="MatchAll"> | |
<add input="{REMOTE_PORT}" pattern=".*" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> | |
</conditions> | |
<action type="Rewrite" url="{R:1}.html" /> | |
</rule> | |
<!-- convert www.website.com to website.com --> | |
<!-- <rule name="Remove WWW" stopProcessing="true"> | |
<match url="(.*)" ignoreCase="true" /> | |
<conditions logicalGrouping="MatchAll"> | |
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" /> | |
</conditions> | |
<action type="Redirect" url="http://{C:1}/{R:0}" appendQueryString="true" redirectType="Permanent" /> | |
</rule> --> | |
</rules> | |
</rewrite> | |
<staticContent> | |
<!-- files allowed to be served --> | |
<remove fileExtension=".mp4" /> | |
<mimeMap fileExtension=".mp4" mimeType="video/mp4" /> | |
<remove fileExtension=".m4v" /> | |
<mimeMap fileExtension=".m4v" mimeType="video/m4v" /> | |
<remove fileExtension=".ogg" /> | |
<mimeMap fileExtension=".ogg" mimeType="video/ogg" /> | |
<remove fileExtension=".ogv" /> | |
<mimeMap fileExtension=".ogv" mimeType="video/ogg" /> | |
<remove fileExtension=".webm" /> | |
<mimeMap fileExtension=".webm" mimeType="video/webm" /> | |
<remove fileExtension=".oga" /> | |
<mimeMap fileExtension=".oga" mimeType="audio/ogg" /> | |
<remove fileExtension=".spx" /> | |
<mimeMap fileExtension=".spx" mimeType="audio/ogg" /> | |
<remove fileExtension=".svg" /> | |
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> | |
<remove fileExtension=".svgz" /> | |
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" /> | |
<!-- fonts --> | |
<remove fileExtension=".otf" /> | |
<mimeMap fileExtension=".otf" mimeType="font/otf" /> | |
<remove fileExtension=".eot" /> | |
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" /> | |
<remove fileExtension=".ttf" /> | |
<mimeMap fileExtension=".ttf" mimeType="application/octet-stream" /> | |
<remove fileExtension=".woff" /> | |
<mimeMap fileExtension=".woff" mimeType="application/font-woff" /> | |
<remove fileExtension=".woff2" /> | |
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" /> | |
<!-- feeds --> | |
<remove fileExtension=".rss" /> | |
<mimeMap fileExtension=".rss" mimeType="application/rss+xml" /> | |
<remove fileExtension=".atom" /> | |
<mimeMap fileExtension=".atom" mimeType="application/atom+xml" /> | |
</staticContent> | |
</system.webServer> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment