【问题标题】:Convert htaccess file to web.config to run Php on IIS 7将 htaccess 文件转换为 web.config 以在 IIS 7 上运行 Php
【发布时间】:2013-02-14 07:25:44
【问题描述】:

我需要将 .htaccess 转换为 web.config 才能在 iis 7 上运行 php。有什么想法吗?

Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /test
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php

【问题讨论】:

  • 我一直不明白为什么人们坚持使用 IIS 来运行 PHP 等问题。但有人告诉我,MS 提供了一个转换工具,它可以自动将 .htaccess 样式文件转换为 IIS 所需的文件。你试过那个工具吗?

标签: .htaccess iis iis-7 web-config url-rewrite-module


【解决方案1】:

从 .htaccess 向导中的 URL 重写模块的导入规则生成了以下规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="non-existent paths to index.php">
          <match url="^test/(.+)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="test/index.php" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

请求/test/ 将导致IIS 触发/test/index.php,因此(.*) 是不必要的,(.+) 更合适。

【讨论】:

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