【问题标题】:Microsoft-IIS/7.5 web.config and .htaccess / Compress .svgMicrosoft-IIS/7.5 web.config 和 .htaccess / 压缩 .svg
【发布时间】:2015-11-17 02:30:47
【问题描述】:

我需要在 Microsoft-IIS/7.5 服务器上建立一个简单的网站。我以前从未这样做过,所以我搜索了一些 web.config sn-ps。一般来说,我对服务器了解不多,但据我了解,IIS 与 web.config 一起使用,而 Apache 与 .htaccess 一起使用。如果我错了,请纠正我。

这是我想出的 web.config:

<?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>

我要做的就是启用 gzip 压缩、缓存文件并删除“.html”结尾。如果同一文件夹中没有 .htaccess,则 Gzipping 和缓存不起作用:

# 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.*

有了这个 .htaccess 就可以了,但这让我很困惑,因为我认为 IIS 服务器需要一个 web.config 来代替 .htaccess?只是 .htaccess 文件也不起作用。有人可以向我解释一下这种行为吗?

2.) 虽然上述方法或多或少有效,但我不知道如何压缩 .svg 文件。我试图上传 .svgz 文件而不是 .svg 文件,但这也没有成功(没有出现)。有什么方法可以压缩 .svg 文件或使用 IIS 服务器支持 .svgz 文件?

提前感谢您的帮助。

【问题讨论】:

    标签: .htaccess iis svg iis-7.5


    【解决方案1】:

    我正在研究如何使 .htaccess 的内容与 IIS 相关,并且我看到了文章 Translate .htaccess Content to IIS web.config

    这可能对你有用。

    【讨论】:

      猜你喜欢
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 2015-05-04
      • 2013-08-25
      • 1970-01-01
      • 2012-01-19
      相关资源
      最近更新 更多