简体   繁体   English

WordPress htaccess代码功能

[英]Wordpress htaccess code functionality

I found this code inside the .htaccess file of a website I have to work on to make a few modifications: 我在必须进行一些修改的网站的.htaccess文件中找到此代码:

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

I'm not an apache expert so I would appreciate your help to clarify (general or specific terms), what does this code do? 我不是apache专家,所以不胜感激您的帮助(通用或特定术语),该代码有什么作用?

Wordpress .htaccess file, explained: Wordpress .htaccess文件,解释为:

The first and last lines starting with # are comments so you know how these rules ended up in your .htaccess file. #开头的第一行和最后一行是注释,因此您知道这些规则如何以.htaccess文件结尾。 WordPress core code uses these comments to locate the related code when it needs to alter the rules for various reasons. WordPress核心代码出于各种原因需要更改规则时,会使用这些注释来查找相关代码。 They do nothing on their own and serve no other purpose. 他们自己什么也不做,没有其他目的。 Any line where the first character is a # is a comment. 第一个字符是#任何行都是注释。

The <IfModule mod_rewrite.c> and </IfModule> lines work as a pair and prevent errors if your server does not have the mod_rewrite.c module installed. <IfModule mod_rewrite.c></IfModule>行可以成对使用,如果服务器未安装mod_rewrite.c模块,则可以防止错误。 If the module is missing, the lines in between are ignored. 如果缺少该模块,则中间的行将被忽略。

RewriteEngine On

This line tells the server to process all following lines beginning with Rewrite* up to the next RewriteEngine line as one logical group. 此行告诉服务器将以下所有以Rewrite *开头的行作为一个逻辑组处理到下一个RewriteEngine行。

RewriteBase /ambienteTrabajo/

This line defines the base from which all relative references are taken. 这行代码定义了所有相关参考的基础。 In this case /ambienteTrabajo/ 在这种情况下,/ ambienteTrabajo /

RewriteRule ^index\.php$ - [L]

This rule prevents any reference to index.php from being processed further down as a permalink, because it's not one. 此规则可防止对index.php的任何引用作为永久链接进一步处理,因为它不是一个。 This will make more sense in a while. 一段时间后,这会更有意义。 As this is the first rewrite rule, with no conditions above it, this rule is always processed. 由于这是第一个重写规则,没有上面的条件,因此始终会处理该规则。 So if the text index.php matches the request portion after the base definition, pass the request along unchanged and do not process any more rules. 因此,如果文本index.php与基本定义之后的请求部分匹配,请沿原样传递请求,并且不再处理其他规则。

RewriteCond %{REQUEST_FILENAME} !-f

engraving of scribeRewriteCond means a condition must be true in order for the next RewriteRule to be processed. 刻下scribeRewriteCond意味着条件必须为真,以便处理下一个RewriteRule。 %{REQUEST_FILENAME} is a variable set by the server to contain the request URL. %{REQUEST_FILENAME}是服务器设置为包含请求URL的变量。 !-f means the condition is true if the first argument does NOT resolve to a valid file. !-f表示如果第一个参数未解析为有效文件,则条件为true。

RewriteCond %{REQUEST_FILENAME} !-d

This is similar to the first condition, except now we're checking for valid directories (the -d flag) instead of files. 这类似于第一个条件,除了现在我们要检查有效目录(-d标志)而不是文件。

RewriteRule . /ambienteTrabajo/index.php [L]

This rule is essentially only processed if the request is some sort of permalink. 本质上仅在请求是某种永久链接的情况下才处理此规则。 Any other valid file system path is passed on without change. 任何其他有效的文件系统路径都将直接传递而无需更改。 Once again, there are two arguments and a flag. 同样,有两个参数和一个标志。 The [L] flag once again means do not process any other rules after this one. [L]标志再次表示在此之后不处理任何其他规则。 There are often no other rules after this, but it is placed here just to be safe. 此后通常没有其他规则,但是为了安全起见,将其放在此处。 The dot . 点。 means match any one character. 表示匹配任何一个字符。 The /index.php means replace the entire original request with /index.php. /index.php表示将整个原始请求替换为/index.php。 If your WordPress installation is above your public html root, you will see the actual folder path here as well. 如果您的WordPress安装位于公共html根目录之上,您还将在此处看到实际的文件夹路径。 This rule basically says send any permalink requests to index.php for further processing by WordPress. 该规则基本上说将任何永久链接请求发送到index.php,以供WordPress进行进一步处理。 WordPress gets the original request from a different variable, so it doesn't matter if it gets rewritten here, WordPress will still know what the original request was. WordPress从另一个变量获取原始请求,因此在这里重写它并不重要,WordPress仍将知道原始请求是什么。

I already know what this code mean. 我已经知道此代码的含义。 firts of all, i have this code in a subdomain that i have for test purpose, this code make the other links of the web site redirect to "/ambienteTrabajo/" and not to the root folder. 首先,我将这段代码放在一个子域中,用于测试目的,此代码使网站的其他链接重定向到“ / ambienteTrabajo /”,而不重定向到根文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM