douzong5473 2013-01-09 05:36
浏览 75
已采纳

URL重写不适用于IIS 7

I have a PHP site deployed on IIS 7 and using URL Rewrite module but my rewrite rules are not working. Below are my actual url and urls I want to show in browser:

Browser URL : http://mydomain.com/myfolder or http://mydomain.com/myfolder/anytext

Actual URL : http://mydomain.com/myfolder/myfile.html

Previously I was using mod rewrite with .htaccess on Wamp server and below are the working rules which were defined in .htaccess file

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

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

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

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^.*$ myfile.html [L]

Below is my web.config file which is not working, Please suggest and help to resolve my problem

<?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>
  • 写回答

2条回答 默认 最新

  • doulifang5554 2013-01-10 12:09
    关注

    After some hit and tries this web.config worked for me

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法