mrksbnch
mrksbnch

Reputation: 1842

Microsoft-IIS/7.5 web.config and .htaccess / Compress .svg

I need to set up a simple website on a Microsoft-IIS/7.5 Server. I've never done that before, so I searched for some web.config snippets. I don't know much about servers in general, but as far as I understood IIS works with web.config, whereas Apache works with .htaccess. Please correct me if I'm wrong.

This is the web.config i came up with:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
            <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
            <dynamicTypes>
                <add mimeType="text/*" enabled="true"/>
                <add mimeType="message/*" enabled="true"/>
                <add mimeType="application/javascript" enabled="true"/>
                <add mimeType="*/*" enabled="false"/>
            </dynamicTypes>
            <staticTypes>
                <add mimeType="text/*" enabled="true"/>
                <add mimeType="message/*" enabled="true"/>
                <add mimeType="application/javascript" enabled="true"/>
                <add mimeType="*/*" enabled="false"/>
            </staticTypes>
        </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
        <caching enabled="true" enableKernelCache="true">
            <profiles>
                <add extension=".asp" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
            </profiles>
        </caching>
        <rewrite>
            <rules>
                <rule name="SEO - Remove .html" stopProcessing="false">
                    <match url="^(.*).html$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}/" />
                </rule>
                <rule name="SEO">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <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>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

All I want to do is enabling gzip compression, caching the files and remove the ".html" ending. Gzipping and caching didn't and still don't work if there is no .htaccess in the same folder:

# CACHING
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

# GZIP
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

With this .htaccess it works, but that somehow confuses me, because I thought IIS Servers need a web.config INSTEAD of a .htaccess? Just the .htaccess file doesn't work either. Can somebody please explain this behaviour to me?

2.) Although the above works more or less, I can't figure out how to compress .svg files. I tried to upload .svgz files instead of .svg files, but that didn't work out either (didn't show up). Is there any way to either compress .svg files or support .svgz files with a IIS server?

Thanks in advance for your help.

Upvotes: 1

Views: 1990

Answers (1)

Rashmi Pandit
Rashmi Pandit

Reputation: 23838

I am investigating on how contents of .htaccess can be made relevant to IIS and I've come across the article Translate .htaccess Content to IIS web.config

This might be useful to you.

Upvotes: 1

Related Questions