Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages. Some anti-theft chain is done by this method.
00x1 start the rewrite engine
There are two ways to write Rewite, one is to write directly in the httpd.conf. One is written in the. htaccess.
00x2 How do I enable Apache rewrite?
- In httpd.conf, find "LoadModule rewrite_module modules/mod_rewrite.so" To remove the # to open Apache rewrite.
- Open. htaccess, is still in the httpd.conf file allowoverride all of the "#" number to remove.
You can view rewrite open information in the Phpinfo interface, Loaded modules view: Mod_rewrite is turned on if it exists.
00x3 Writing rewrite code:
- If you want to enter it directly in httpd.conf, enter it at the end of the </IfModule> tab.
2. Write in htaccess. It is not allowed to create such a file in Windows, so how do we build it? First build a htaccess.txt can enter cmd, type: Rename Htaccess.txt. htaccess you can generate a. htaccess file. Simply build a txt and rename it to htaccess using CMD.
00x4 Rewrite rule learning
Once the new. htaccess file has been created, use Notepad to open it. Start learning rewrite rules.
Start the first case:
Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭RewriteRule ^ (. *?). HTML 1.php?id=$1
Rewriterule is a rewrite rule. The following is the regular.
1.php of code:
<?php echo $_get[' id '];?>
After writing the rewrite, restart Apache. Then visit 127.0.0.1/t_test.html
The effect of the output is as follows:
The successful implementation of pseudo-static.
This is just a file to write pseudo-static, we can also write in a folder way
Directly on the basis of the use of the regular ($) function to operate. The code is as follows:
Rewriteengine onrewriterule ^t_ (. *)/$ 1.php?id=$1
You can write whatever you like.
Related knowledge
Mod_rewrite rule modifier
- 1) R Force external redirection
- 2) F disable URL, return 403HTTP status code.
- 3) G force URL is gone, return 410HTTP status code.
- 4) P forces the use of proxy forwarding.
- 5) L indicates that the current rule is the last rule, which stops the rewrite of the rule after parsing.
- 6) N re-run the rewrite process starting with the first rule.
- 7) C is associated with the next rule 8) T=mime-type (Force MIME type) enforces MIME type
- 9) NS is only used for internal sub-requests
- NC is case insensitive
- One) QSA Append request string
- NE not output escape special character \%3d$1 equivalent to =$1
Apache Rewrite quasi-static