这个 .htaccess 代码是什么意思?

发布于 2024-10-03 09:57:57 字数 193 浏览 0 评论 0原文

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

我认为这意味着如果 url 与服务器上的文件或目录不匹配,请转到 /index.php?

有人可以确认吗?

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

I think it means if the url doesn't match a file or directory on the server go to /index.php?

Can anybody confirm?

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

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

发布评论

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

评论(2

蓦然回首 2024-10-10 09:57:57

是的,这是简短的答案。但通常 ./index.php 具有 [L,QSA] 后缀/限定符,因此 URI 请求的查询部分也会传递给它。

Yes is the short answer. But usually ./index.php has an [L,QSA] suffix/qualifier, so the query part of a URI request is also passed on to it.

感情洁癖 2024-10-10 09:57:57

这是在做什么:

RewriteCond %{REQUEST_FILENAME} !-d

如果找不到该名称的目录

RewriteCond %{REQUEST_FILENAME} !-f

如果找不到该名称的文件

重写规则.* ./index.php

加载.htaccess 文件旁边的index.php。

 

回答安东尼关于如果删除它会发生什么的问题1 2

它会尝试访问目录或文件。如果失败,它不会默认使用 index.php,而是简单地给出默认 Web 服务器 404 错误。

现在,它允许应用程序显示默认页面,或通过它以某种方式处理请求。

What this is doing:

RewriteCond %{REQUEST_FILENAME} !-d

If it can't find a directory with the name

RewriteCond %{REQUEST_FILENAME} !-f

If it can't find a file with the name

RewriteRule .* ./index.php

Load the index.php next to the .htaccess file.

 

To answer Anthony's question regarding what would happen if it where removed1 2,

It would try and access the directory or file. If it fails, instead of defaulting to the index.php it would simply give the default web servers 404 error.

Right now, it allows the application to either show the default page, or handle the request through it in some fashion.

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