将htaccess文件转换为web.config以在IIS 7上运行Php

时间:2013-02-14 07:25:45

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

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

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

1 个答案:

答案 0 :(得分: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,因此不需要(.*)(.+)更合适。