【发布时间】: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 文件?
提前感谢您的帮助。
【问题讨论】: