【问题标题】:My .htaccess file doesn't work on IIS我的 .htaccess 文件在 IIS 上不起作用
【发布时间】:2011-08-09 15:19:27
【问题描述】:

我的.htaccess 文件中有以下重写配置,该配置在 apache 服务器中运行良好,但在 IIS 服务器中无法正常运行。

选项 +FollowSymlinks 重写引擎开启 RewriteCond %{HTTP_HOST} ^myservername/$ [NC] RewriteRule ^(.*)$ http://myservername/$1 [R=301,L] RewriteRule !\.(php|png|gif|jpg|css|htm|html|txt|js|swf|xml|ico|mp3|csv|wav|mid) /index.php [L,QSA]

如何让这个在 IIS 上工作?

【问题讨论】:

  • 你没有。 .htaccess 文件是特定于 Apache 的。

标签: apache iis .htaccess


【解决方案1】:

IIS 不支持开箱即用的.htaccess。要在 IIS 上使用 Apache 风格的 mod_rewrite 规则,您需要第三方重写器,例如 Iconics ISAPI Rewrite Filter 或 HeliconTech 的 ISAPI_Rewrite。您可能需要调整重写规则,因为并非所有 mod_rewrite 的指令都受支持或适用(因为 Windows 不是 Unix)。

如果您运行的是 IIS7 并且它安装了 UrlRewriter(它是免费的),您可以使用它,但您需要将重写规则转换为完全不同的格式。

【讨论】:

    【解决方案2】:

    请创建名为 web.config 的新文件并粘贴以下内容

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Imported Rule 1" stopProcessing="true">
                        <match url="^.*$" />
                        <conditions logicalGrouping="MatchAny">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile"  />                      
                        </conditions>
                        <action type="None" />
                    </rule>
                    <rule name="Imported Rule 2" stopProcessing="true">
                        <match url="^(.*)$" />
                        <action type="Rewrite" url="index.php" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 2015-02-23
      • 1970-01-01
      相关资源
      最近更新 更多