将 .htaccess 转换为 web.config

发布于 2024-10-05 18:39:50 字数 366 浏览 0 评论 0原文

我在运行 IIS 的虚拟 Windows 服务器上托管一个 php 应用程序。

为我编写php网站的人要求我将这段代码放在.htaccess中:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

但是由于该应用程序在IIS上运行,因此我需要将这段代码翻译为web.config。我怎样才能将它们翻译成web.config?

I am hosting a php application on my virtual Windows server running IIS.

The person who wrote the php website for me asked me to put this piece of codes in a .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

But as this application is running on IIS, I need to translate this piece of codes to web.config. How can I translate them into web.config?

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

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

发布评论

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

评论(1

茶花眉 2024-10-12 18:39:50

此 htaccess 代码的作用是将任何可能导致 404 错误(!-f 和 !-d 表示“文件不存在”和“目录不存在”)的请求重定向到 /index.php。

IIS7 具有导入 mod_rewrite 规则的功能 - 只需使用此功能:

  1. 启动 IIS 管理器。
  2. 在左侧的“连接”窗格中,选择“默认网站”。
  3. 在右侧的功能视图中,单击 URL 重写。
  4. 在右侧的操作窗格中,单击导入规则。
  5. 复制 mod_rewrite 规则并将其粘贴到重写规则文本框中。
  6. 转换规则框的树视图选项卡立即显示转换结果。您还可以单击“XML 视图”选项卡来查看规则如何存储在 Web.config 文件中。

来源

What this htaccess code does is redirecting any requests which would otherwise result in a 404 error (!-f and !-d mean "file does not exist" and "dir does not exist") to /index.php.

IIS7 has a feature to import mod_rewrite rules - simply use this:

  1. Start IIS Manager.
  2. On the left, in the Connections pane, select Default Web Site.
  3. On the right, in Features View, click URL Rewrite.
  4. On the right, in the Actions pane, click Import Rules.
  5. Copy your mod_rewrite rules and paste them into the Rewrite rules text box.
  6. The Tree View tab of the Converted Rules box instantly shows the result of the conversion. You can also click the XML View tab to see how the rules are stored in the Web.config file.

(Source)

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