IIS7+ - 如何让Url Rewrite Outbound Rule和Dynamic Compression同时工作

来源:互联网 发布:钉钉软件使用说明 编辑:程序博客网 时间:2024/06/05 20:38

很多用过Url Rewrite Outbound Rule的都知道Url Rewrite Outbound Rule不能重写被压缩过的response,如果compression和url rewrite outbound rule同时使用,会导致一个由url rewrite模块所抛出的500.52错误。对于这个问题,本人所见过的网上大多的解决方法是disable compression。然而有没有方法使2者同时工作呢?答案是有的,步骤如下:

首先,你需要在注册表里添加个名为LogRewrittenUrlEnabled的键并赋值为0

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled /t REG_DWORD /d 0

然后,你需要将dynamicCompressionBeforeCache设为false:

%windir%\system32\inetsrv\appcmd set config "Your Site Name" -section:system.webServer/urlCompression /dynamicCompressionBeforeCache:"False"

最后也是最重要,就是确保url rewrite模块在compression模块之前执行。说到这点很多人会在模块顺序中把RewriteModule移到DynamicCompressionModule的前面,看似合情合理但这是错误的!原因在于当一个outbound请求发生的时候,模块执行的顺序是和列表显示的是相反的,所以将RewriteModule置于DynamicCompressionModule之下才是使rewrite模块在outbound过程中先于compression工作的正确操作。

完成以上3点后,做一个测试,我们就会欣喜地发现url rewrite outbound rule和dynamic compression能同时工作了。