php 这是 WordPress 中的 .htaccess 代码。有人可以解释它是如何工作的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5061880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
This is the .htaccess code in WordPress. Can someone explain how it works?
提问by webnat0
This is the .htaccess code for permalinks in WordPress. I don't understand how this works. Can someone explain?
这是 WordPress 中永久链接的 .htaccess 代码。我不明白这是如何工作的。有人可以解释一下吗?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I googled and found out that -f
and -d
part means to give real directories and files higher priority.
我用Google搜索,并发现-f
和-d
部分手段给予真正的目录和文件更高的优先级。
But then what are ^index\.php$ - [L]
and RewriteRule . /index.php [L]
?
但是,什么是^index\.php$ - [L]
和RewriteRule . /index.php [L]
?
How does WordPress process categories, tags, pages, and etc. with just this?
WordPress 如何处理类别、标签、页面等。
Does it happen internally? If so, I'm interested in learning how to do it in PHP.
它发生在内部吗?如果是这样,我有兴趣学习如何在 PHP 中做到这一点。
Thanks
谢谢
回答by Kevin Stricker
^index\.php$ - [L]
prevents requests for index.php
from being rewritten, to avoid an unnecessary file system check. If the request is for index.php
the directive does nothing -
and stops processing rules [L]
.
^index\.php$ - [L]
防止请求index.php
被重写,以避免不必要的文件系统检查。如果请求是针对index.php
指令的,则不执行任何操作-
并停止处理规则[L]
。
This block is all one rule, and it says that if it is not a real file and not a real directory, reroute the request to index.php
.
这个块是一个规则,它说如果它不是一个真正的文件和一个真正的目录,则将请求重新路由到index.php
.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
index.php itself interprets the URL that was requested by the client (PHP can see the requested URL using $_SERVER['REQUEST_URI']
) and it calls the correct code for rendering the page the user requested.
index.php 本身解释客户端请求的 URL(PHP 可以使用 看到请求的 URL $_SERVER['REQUEST_URI']
)并调用正确的代码来呈现用户请求的页面。