Php URL重写在IIS 7上不起作用

Php URL重写在IIS 7上不起作用,php,iis-7,url-rewriting,Php,Iis 7,Url Rewriting,我在IIS7上部署了一个PHP站点,并使用URL重写模块,但我的重写规则不起作用。下面是我的实际url和我想在浏览器中显示的url: 浏览器URL:或 实际网址: 以前我在Wamp服务器上使用mod rewrite with.htaccess,下面是在.htaccess文件中定义的工作规则 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^(.+)/$ RewriteRule ^

我在IIS7上部署了一个PHP站点,并使用URL重写模块,但我的重写规则不起作用。下面是我的实际url和我想在浏览器中显示的url:

浏览器URL:或

实际网址:

以前我在Wamp服务器上使用mod rewrite with.htaccess,下面是在.htaccess文件中定义的工作规则

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} ^(.+)/$

RewriteRule ^(.+)/$  /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^.*$ myfile.html [L]
下面是我的web.config文件,它不工作,请建议并帮助解决我的问题

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Rewrite to myfile.html1">
                <match url="^(.+)/$" />
                <action type="Rewrite" url="/$1" />
            </rule>
        </rules>
        <rules>
            <rule name="Rewrite to myfile.html2">
                <match url="^.*$" />
                <action type="Rewrite" url="myfile.html" />
            </rule>
        </rules>
    </rewrite>
    </system.webServer>
</configuration>

访问
.htaccess
规则实际上在做两件不同的事情。首先,它确保以
/
(斜杠)结尾的请求被重定向到不带斜杠和结尾的URL。第二条规则将所有不存在文件的请求重写为
myfile.html

这应该有效(未经测试):


经过一番尝试后,这个web.config对我很有效

<?xml version="1.0" encoding="UTF-8"?>
   <configuration>
      <system.webServer>
         <directoryBrowse enabled="true" />
         <rewrite>
            <rules>
               <rule name="Rule1" stopProcessing="true">
                  <match url="^(.+)/$" />
                  <conditions>
                     <add input="{URI}" pattern="^(.+)/$" />
                     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                  </conditions>
                  <action type="Rewrite" url="/$1" />
               </rule>
               <rule name="Rule2" stopProcessing="true">
                  <match url="^myfolder/.*$" />
                  <conditions>
                     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  </conditions>
                 <action type="Rewrite" url="myfolder/myfile.html" />
              </rule>
           </rules>
        </rewrite>
     </system.webServer>
  </configuration>

此web配置显示500.19内部服务器错误。可能是因为定义了两个规则标记。我过去也遇到过这个错误。两个
标记应该组合在一个
部分中,然后它应该可以工作。
<?xml version="1.0" encoding="UTF-8"?>
   <configuration>
      <system.webServer>
         <directoryBrowse enabled="true" />
         <rewrite>
            <rules>
               <rule name="Rule1" stopProcessing="true">
                  <match url="^(.+)/$" />
                  <conditions>
                     <add input="{URI}" pattern="^(.+)/$" />
                     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                  </conditions>
                  <action type="Rewrite" url="/$1" />
               </rule>
               <rule name="Rule2" stopProcessing="true">
                  <match url="^myfolder/.*$" />
                  <conditions>
                     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  </conditions>
                 <action type="Rewrite" url="myfolder/myfile.html" />
              </rule>
           </rules>
        </rewrite>
     </system.webServer>
  </configuration>