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条)

报告相同问题?

悬赏问题

  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化