这是 WordPress 中的 .htaccess 代码.有人可以解释它是如何工作的吗? [英] This is the .htaccess code in WordPress. Can someone explain how it works?

查看:26
本文介绍了这是 WordPress 中的 .htaccess 代码.有人可以解释它是如何工作的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 WordPress 中永久链接的 .htaccess 代码.我不明白这是如何工作的.谁能解释一下?

This is the .htaccess code for permalinks in WordPress. I don't understand how this works. Can someone explain?

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

我用谷歌搜索发现 -f-d 部分意味着给予真实目录和文件更高的优先级.

I googled and found out that -f and -d part means to give real directories and files higher priority.

但是什么是 ^index\.php$ - [L]RewriteRule ./index.php [L] ?

But then what are ^index\.php$ - [L] and RewriteRule . /index.php [L] ?

WordPress 如何处理类别、标签、页面等?

How does WordPress process categories, tags, pages, and etc. with just this?

它是否发生在内部?如果是这样,我有兴趣学习如何在 PHP 中做到这一点.

Does it happen internally? If so, I'm interested in learning how to do it in PHP.

谢谢

推荐答案

^index\.php$ - [L] 防止对 index.php 的请求被重写, 以避免不必要的文件系统检查.如果请求是针对 index.php 的,则指令什么都不做 - 并停止处理规则 [L].

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

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.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

index.php 本身解释客户端请求的 URL(PHP 可以使用 $_SERVER['REQUEST_URI'] 查看请求的 URL)并调用正确的代码来呈现页面用户请求.

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.

这篇关于这是 WordPress 中的 .htaccess 代码.有人可以解释它是如何工作的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆