【问题标题】:Converting .htaccess (PHP) line to web.config line (IIS)将 .htaccess (PHP) 行转换为 web.config 行 (IIS)
【发布时间】:2014-12-14 23:07:44
【问题描述】:

我的 .htaccess 文件中有这些行,并且已将我的站点移至 IIS 环境。我很确定它需要进入根目录中的 web.config 文件,但我完全迷失了,尝试了一切都没有运气。它的作用是将任何带有 .php、.htm 或 .html 的内容定向到根目录中的 index.php 页面,这样我就可以控制显示的内容并使之模块化。它将附加查询字符串中的文件名,以便我可以从那里引导内容。无论如何,这就是我所拥有的 .htaccess:

RewriteCond %{REQUEST_FILENAME} (\.php|.htm|.html)$
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

【问题讨论】:

    标签: .htaccess web-config rewrite iis-7.5


    【解决方案1】:

    您可以使用此 Microsoft 支持的 URL Rewrite IIS Manager module 导入并将 mod_rewrite rules 转换为 IIS URL rewrite rules

    web.config

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Rule 1" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" pattern="\.(php|htm|html)$" ignoreCase="false" />
                        </conditions>
                        <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    【讨论】:

      【解决方案2】:

      非常感谢您将我指向 url 重写模块的方向。我已经尝试过使用它,但不知道它具有导入功能!在我导入 .htaccess 行后,它仍然无法正常工作(正如导入 lol 所预期的那样),但在我稍微调整了 reqex 之后,一切正常!!!再次感谢您帮助我。对于任何想要正确的 web.config 设置的人来说,这里是:)

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Imported Rule 1" stopProcessing="true">
                          <match url="^(.*)$" ignoreCase="false" />
                          <conditions logicalGrouping="MatchAll">
                              <add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="(.*php|.*htm|.*html)$" ignoreCase="true" negate="false" />
                          </conditions>
                          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>
      

      【讨论】:

        猜你喜欢
        • 2022-01-22
        • 2012-01-30
        • 1970-01-01
        • 2019-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多