【问题标题】:What's the IIS equivalent of these rewrite rules?这些重写规则的 IIS 等价物是什么?
【发布时间】:2011-05-20 20:03:33
【问题描述】:

我一直使用 apache,所以我对 IIS 完全陌生。我将如何在 IIS 中执行此操作?

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

我打开了 IIS 管理器,正在查看“URL 重写”,然后单击了“添加规则”。我想这就是我想去的地方,但我不知道从这里去哪里。


对于那些知道 IIS 但不知道 apache 的 mod_rewrite 的人,它只是检查请求是否不是目录或文件,如果是,则获取请求 url 并将其作为 GET 参数传递给 index.php,而不是这样可以通过路由器在代码中进行处理。

【问题讨论】:

    标签: apache iis mod-rewrite iis-7 url-rewriting


    【解决方案1】:

    您可以自动导入它们,只需转到您想要的站点或应用程序并双击 URL 重写图标,然后使用任务列表中的导入规则...链接。 在该 UI 中,只需复制/粘贴上面的规则并单击“确定”,它就会将这些规则导入您的 web.config。

    您的 web.config 中的等价物将是(当然在 configuration/system.webServer...等内部):

    <rewrite>  
      <rules>  
        <rule name="Imported Rule 1" stopProcessing="true">  
          <match url="^(.*)$" ignoreCase="false" />  
          <conditions>  
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />  
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />  
          </conditions>  
          <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />  
        </rule>  
      </rules>  
    </rewrite>  
    

    有关如何导入它们的更多信息:http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules/

    【讨论】:

      【解决方案2】:

      您发布的 htaccess 行看起来与 Zend Framework 使用的非常相似。他们有一个重写配置指南,上面有a section on IIS 7.0

      【讨论】:

        猜你喜欢
        • 2011-10-22
        • 2019-02-04
        • 2011-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-22
        • 2011-03-19
        相关资源
        最近更新 更多