Precompressed files Rewrite rules IISRSS

2 replies

Last post 14 hours, 24 minutes ago by Brucz

‹ Previous Thread|Next Thread ›
  • Precompressed files Rewrite rules IIS

    Nov 16, 2020 02:31 AM|joey_castell|LINK

    Hi guys,

    I am using IIS 8.5.

    I am deploying a .NET core website with a Angular front end.

    My Angular file structure is stored ClientApp/dist all files have been pre compressed and I would like IIS to serve this instead of using dynamic compression to save on CPU.

    I have been looking into this and I am a bit stuck, I have the following web config which I have used from a stackoverflow question:

     <system.webServer>
        <staticContent>
    <remove fileExtension=".gz" /> <remove fileExtension=".js.gz" /> <remove fileExtension=".css.gz" /> <remove fileExtension=".png.gz" /> <remove fileExtension=".jpg.gz" /> <remove fileExtension=".gif.gz" /> <remove fileExtension=".svg.gz" /> <remove fileExtension=".html.gz" /> <remove fileExtension=".json.gz" /> <mimeMap fileExtension=".js.gz" mimeType="application/javascript" /> <mimeMap fileExtension=".css.gz" mimeType="text/css" /> <mimeMap fileExtension=".png.gz" mimeType="image/png" /> <mimeMap fileExtension=".jpg.gz" mimeType="image/jpeg" /> <mimeMap fileExtension=".gif.gz" mimeType="image/gif" /> <mimeMap fileExtension=".svg.gz" mimeType="image/svg+xml" /> <mimeMap fileExtension=".html.gz" mimeType="text/html" /> <mimeMap fileExtension=".json.gz" mimeType="application/json" /> </staticContent> <rewrite> <outboundRules rewriteBeforeCache="true"> <rule name="Custom gzip file header"> <match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" /> <conditions> <add input="{REQUEST_URI}" pattern="\.gz$" /> </conditions> <action type="Rewrite" value="gzip"/> </rule> </outboundRules> <rules> <rule name="Rewrite gzip file"> <match url="(.*)"/> <conditions> <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" /> <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" /> </conditions> <action type="Rewrite" url="{R:1}.gz" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

    However it is not serving the compressed files. (Please note I have disabled static & dynamic compression).

    It should be performing a rewrite on the following conditions:

    1. Client side accepts gzip
    2. Response with header content encoding
    3. Proper MIME type
    4. Gzip file exists

    The problem seems to be this condition:

    <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />

    As when I remove the rule the precompressed files are transmitted but then API requests are rewritten incorrectly.

    Any help with this would be much appreciated as I don't have any experience with the rewrite module.

    Many thanks

  • Re: Precompressed files Rewrite rules IIS

    Nov 17, 2020 03:48 AM|Brucz|LINK

    Hi jeoy_castell,

    As you have discovered,

    joey_castell

    The problem seems to be this condition:

    <add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />

    This is not the correct conditional format. There is no ".gz" after {REQUEST_FILENAME}.  

    If you want to judge whether it is a file, matchType = "IsFile", if you want to judge its name, pattern = the regular expression you defined.

    Best Regards,

    Brucz

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: Precompressed files Rewrite rules IIS

    14 hours, 24 minutes ago|Brucz|LINK

    Hi joey_castell,

    Does this solution solve your problem? If not, you can post the new problem.

    Best regards,

    Brucz

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
‹ Previous Thread|Next Thread ›