简体   繁体   中英

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:

#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?

Wordpress .htaccess file, explained:

The first and last lines starting with # are comments so you know how these rules ended up in your .htaccess file. WordPress core code uses these comments to locate the related code when it needs to alter the rules for various reasons. 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. 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.

RewriteBase /ambienteTrabajo/

This line defines the base from which all relative references are taken. In this case /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. 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.

RewriteCond %{REQUEST_FILENAME} !-f

engraving of scribeRewriteCond means a condition must be true in order for the next RewriteRule to be processed. %{REQUEST_FILENAME} is a variable set by the server to contain the request URL. !-f means the condition is true if the first argument does NOT resolve to a valid file.

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.

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. 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. If your WordPress installation is above your public html root, you will see the actual folder path here as well. This rule basically says send any permalink requests to index.php for further processing by 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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