Learn Apache's rewrite syntax based on the. htaccess file in ZF

Source: Internet
Author: User

First, let's take a look at this. htaccess file:

Rewriteengine Onrewritecond%{request_filename}-S [Or]rewritecond%{request_filename}-l [OR]RewriteCond%{REQUEST_ FILENAME}-drewriterule ^.*$-[Nc,l]rewriterule ^.*$ index.php [nc,l]

There are 3 instructions involved:

1, Rewriteengine the simplest, control the switch of the redirection engine. The first instruction indicates that the redirection engine is turned on.

2, Rewritecond instruction is slightly more complicated. Each of these instructions defines a condition, and the rewriterule that follows this command will only work if the condition is met. Note: This command only provides conditions for a subsequent rewriterule command! For example, the second rewriterule instruction in the above file does not need to be executed until the previous Rewritecond instruction is satisfied.

If you want to judge more than one condition at a time, you can add the [OR] flag at the end to indicate that you are not ending your judgment and continue to see the next rewritecond instruction.

The second parameter of this instruction is the value to be judged, here is the server variable%{request_filename}

The third parameter is the matching pattern, the number of matching patterns used in the file means:

-S to determine whether the second parameter is a regular file with a size greater than 0 that exists on the server;

-L to determine whether the second parameter is present on the server, the symbolic link file;

-D to determine if the second parameter is a folder that exists on the server;

If any of these three articles is met, the first rewriterule instruction is executed.

3, then let us look at the rewriterule directive.

The second parameter of the Rewriterule directive is a regular expression. The first function of the Rewriterule directive is applied to the requested URL address (UrlEncode), and the subsequent rewriterule instruction applies the regular to the result of the previous instruction.

The third parameter of this instruction is the value to be replaced. -The representation remains intact, not replaced.

This command can also be marked after. For example, the NC flag means that the no CASE,L flag is to stop the execution of the following rewriterule instructions.

Therefore, the ZF file means that if it is a file that exists on the server, do not redirect it, or redirect to index.php if the file in the request path does not exist.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.