这些重写规则的 IIS 等效项是什么?

发布于 2024-10-06 20:38:27 字数 393 浏览 0 评论 0原文

我一直使用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,以便它可以通过路由器在代码中处理。

I've always used apache, so I'm completely new to IIS. How would I do this in IIS?

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

I've got IIS Manager open, and I'm looking at "URL Rewrite" and just clicked "Add Rule(s)". I assume this is the place I want to be, but I don't know where to go from here.


For those of you who know IIS but not apache's mod_rewrite, it just checks if the request is NOT a directory nor a file, and if so, takes the request url and passes it to index.php as a GET param instead so that it can be handled in code, with a router.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-10-13 20:38:27

您可以自动导入它们,只需转到所需的站点或应用程序并双击 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/

You can import them automatically, just go to the Site or Application you want and double click URL Rewrite icon, then use the Import Rules... link in the task list.
In that UI, just copy/paste the rules above and click OK, it will import those to your web.config.

The equivalent in your web.config would be (of course inside configuration/system.webServer...etc):

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

For more information on how to import them: http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules/

假面具 2024-10-13 20:38:27

您发布的 htaccess 行看起来与 Zend Framework 使用的非常相似。他们有一个重写配置指南,其中有 a有关 IIS 7.0 的部分

The htaccess lines you posted look very similar to what is used by Zend Framework. They have a rewrite configuration guide that has a section on IIS 7.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文