但是 css 如果有設定下載字型檔 .ttf or .woff
就會出現 CORS 問題,其他 js, css,圖片就能正常
為了解決CORS的問題,其實只要 Response Header 要設定 Access-Control-Allow-Origin: *
或是設定特定網站 Access-Control-Allow-Origin: https://www.s3.com.tw
後來發現 IIS 網站可以設定 web.config 設定 response header 解決
當然要先裝一下 urlrewrite 2.0 才可以使用
只針對 font 類型的靜態檔
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Add CORS header for fonts" preCondition="IsFontFile">
<match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern=".*" />
<action type="Rewrite" value="*" />
</rule>
<preConditions>
<preCondition name="IsFontFile">
<add input="{REQUEST_URI}" pattern="\.woff2$|\.woff$|\.ttf$|\.eot$|\.otf$" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
{REQUEST_URI} 也可以改為 {PATH_INFO}