我有一个问题,我在清除IIS上的WP Rocket缓存(我有一条将用户直接指向.html缓存文件的规则)后,在几秒钟内获得404s。
为了解决这个问题,我想在我的web.config中添加一条规则,当WP Rocket正在执行某些操作时,该规则会禁用direct-to-html-cache规则。
我已经连接到插件,并根据缓存插件是否忙碌设置一个等于true或false的PHP环境变量。
如何在web.config中使用此环境变量?
这是我的web.config,以防你们任何人试图在IIS上的任何PHP上提供WP Rocket文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Vary" />
<add name="Vary" value="Accept-Encoding" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="X-UA-Compatible" value="IE=Edge" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<!--<serverRuntime enabled="true" frequentHitThreshold="1" frequentHitTimePeriod="00:30:00" />-->
<!--<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".html" duration="3:00:00" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
</profiles>
</caching>-->
<rewrite>
<rules>
<clear/>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false"
/>
</rule>
<rule name="WP Rocket" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern=".*=.*" negate="true" />
<add input="{QUERY_STRING}" pattern=".*attachment_id=.*" negate="true" />
<add input="{HTTP_COOKIE}" pattern="^.*(comment_author_|wordpress|wp-postpass_).*$" negate="true" />
<!--<add input="{WP_ROCKET_BUSY}" pattern="true" negate="true">-->
<add input="{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/{HTTP_HOST}/{R:1}index-https.html" matchType="IsFile"
/>
</conditions>
<action type="Rewrite" url="wp-content/cache/wp-rocket/{HTTP_HOST}/{R:1}index-https.html" />
</rule>
<rule name="Check backup folder if CSS/JS does not exist in primary directory" stopProcessing="true">
<match url="wp-content\/cache\/min\/1\/(.*)" />
<conditions>
<add input="{DOCUMENT_ROOT}/wp-content/cache/min/1/{R:1}" matchType="IsFile" negate="true" />
<add input="{DOCUMENT_ROOT}/wp-content/cache/min/backup/{R:1}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="wp-content/cache/min/backup/{R:1}" />
</rule>
<rule name="Wordpress Pretty Permalinks" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<httpErrors errorMode="Detailed" />
<!--<directoryBrowse enabled="false" />-->
<!--<validation validateIntegratedModeConfiguration="false" />-->
<!-- Microsoft sets runAllManagedModulesForAllRequests to true by default
You should handle this according to need, but consider the performance hit.
Good source of reference on this matter: http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78
-->
<!--<modules runAllManagedModulesForAllRequests="false" />-->
<!--<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />-->
<staticContent>
<!-- Remove ETAG IN IIS >8 ; for IIS 7/7.5 see the Rewrite rules (bigger description of why you might remove etag down there aswell)
<clientCache setEtag="false"/>
-->
<!-- Set expire headers to 30 days for static content-->
<clientCache cacheControlCustom="public" cacheControlMaxAge="30.00:00:00" cacheControlMode="UseMaxAge" />
<remove fileExtension=".html" />
<mimeMap fileExtension=".html" mimeType="text/html; charset=UTF-8" />
<remove fileExtension=".css" />
<mimeMap fileExtension=".css" mimeType="text/css" />
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="text/javascript" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<remove fileExtension=".rss" />
<mimeMap fileExtension=".rss" mimeType="application/rss+xml; charset=UTF-8" />
<remove fileExtension=".xml" />
<mimeMap fileExtension=".xml" mimeType="application/xml; charset=UTF-8" />
<remove fileExtension=".mp3" />
<mimeMap fileExtension=".mp3" mimeType="audio/mpeg" />
<remove fileExtension=".mp4" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<remove fileExtension=".ogg" />
<mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
<remove fileExtension=".ogv" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<remove fileExtension=".webm" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<remove fileExtension=".svgz" />
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<remove fileExtension=".ttf" />
<mimeMap fileExtension=".ttf" mimeType="application/x-font-ttf" />
<remove fileExtension=".ttc" />
<mimeMap fileExtension=".ttc" mimeType="application/x-font-ttf" />
<remove fileExtension=".otf" />
<mimeMap fileExtension=".otf" mimeType="font/opentype" />
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
<remove fileExtension=".crx" />
<mimeMap fileExtension=".crx" mimeType="application/x-chrome-extension" />
<remove fileExtension=".xpi" />
<mimeMap fileExtension=".xpi" mimeType="application/x-xpinstall" />
<remove fileExtension=".safariextz" />
<mimeMap fileExtension=".safariextz" mimeType="application/octet-stream" />
<remove fileExtension=".flv" />
<mimeMap fileExtension=".flv" mimeType="video/x-flv" />
<remove fileExtension=".f4v" />
<mimeMap fileExtension=".f4v" mimeType="video/mp4" />
<remove fileExtension=".ico" />
<mimeMap fileExtension=".ico" mimeType="image/x-icon" />
<remove fileExtension=".webp" />
<mimeMap fileExtension=".webp" mimeType="image/webp" />
<remove fileExtension=".htc" />
<mimeMap fileExtension=".htc" mimeType="text/x-component" />
<remove fileExtension=".vcf" />
<mimeMap fileExtension=".vcf" mimeType="text/x-vcard" />
<remove fileExtension=".torrent" />
<mimeMap fileExtension=".torrent" mimeType="application/x-bittorrent" />
<remove fileExtension=".cur" />
<mimeMap fileExtension=".cur" mimeType="image/x-icon" />
<remove fileExtension=".webapp" />
<mimeMap fileExtension=".webapp" mimeType="application/x-web-app-manifest+json; charset=UTF-8" />
</staticContent>
</system.webServer>
</configuration>