First, let's take a look at the. htaccess file:
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]
Three commands are involved:
1. RewriteEngine is the simplest and controls the switch of the redirection engine. The first command indicates opening the redirection engine.
2. The RewriteCond command is slightly more complex. Each Command defines a condition. Only when this condition is met Will the RewriteRule following this command take effect.Note: This command only provides conditions for the subsequent RewriteRule command!For example, the second RewriteRule command in the above file does not need to be executed only when the previous RewriteCond command meets the requirements.
If you want to judge multiple conditions at the same time, you can add the [OR] mark to the end of the judgment, indicating that the judgment is not terminated for the time being. Continue to read the next RewriteCond command.
The second parameter of this command is the value to be determined. Here is the server variable % {REQUEST_FILENAME}
The third parameter is the matching mode. The following match modes are used in the file:
-S: determines whether the second parameter is a regular file on the server with a size greater than 0;
-L determine whether the second parameter exists on the server and the symbolic link file;
-D: determines whether the second parameter is a folder on the server;
If any of the three rules is met, the first RewriteRule command is executed.
3. Let's look at the RewriteRule command.
The second parameter of the RewriteRule command is a regular expression. The Regular Expression of the first RewriteRule command will be applied to the request URL (urlencode); then the RewriteRule command will apply the regular expression to the result of the previous command.
The third parameter of this command is the value to be replaced. -This parameter is left unchanged and is not replaced.
This command can also be followed by a flag. For example, the NC mark means no case, and the L mark means to stop the execution of the following RewriteRule command.
Therefore, the ZF file means that if it is a file on the server, do not redirect it. If the file in the Request Path does not exist, redirect it to index. php.