1. Detect if Apache supports Mod_rewrite
View the environment configuration through the Phpinfo () function provided by PHP, and find the "Loaded Modules" through the ctrl+f, which lists all the modules that Apache2handler have opened, and if it includes "mod_rewrite", it has been supported, You no longer need to continue setup.
If "Mod_rewrite" is not turned on, open the directory under your Apache installation directory "/apache/conf/" under the httpd.conf file, through ctrl+f find "LoadModule rewrite_module", the previous " # "number deleted."
If it is not found, go to the LoadModule area, add "LoadModule rewrite_module modules/mod_rewrite.so" (the required exclusive line) on the last line, and then restart the Apache server.
2. Let Apache server support. htaccess
How do I get my local Apache server to support ". htaccess"? In fact, as long as a simple change to the Apache httpd.conf settings can let Apache support. htaccess. Open the httpd.conf file (where?) Apache directory, with a text editor open, find
Copy Code code as follows:
Options FollowSymLinks
AllowOverride None
To
Copy Code code as follows:
Options FollowSymLinks
AllowOverride All
It's OK.
3. Establishment of. htaccess Documents
If it is under the Windows platform, at the beginning really do not know how to build ". htaccess" file, because this file does not actually have a filename, only the extension, through the normal way is not able to create this file, don't worry, I'll tell you at once. Three methods: Three methods are to create a htaccess.txt text file (of course, the name of the text file you can arbitrarily take), and then there are three ways to rename the file:
(1) Open with Notepad, click on the file – Save As, enter ". htaccess" in the filename window, note that the entire green section, which contains the English quotes, then click Save on the line.
(2) Enter the cmd command window, switch on CD when you have just established the Htaccess.txt file folder, and then enter the command: Rename Htaccess.txt. htaccess, then click the Keyboard enter button.
(3) through the FTP connection Htaccess.txt folder, through the FTP software rename.
4.rewrite Rule Learning
After we create a new. htaccess file, we write the following in it:
Copy Code code as follows:
Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭
Rewriterule ([0-9]{1,}) $ index.php?id=$1
Let me explain. Rewriterule:rewriterule is an overriding rule that supports regular expressions, and the above ([0-9]{1,}) is a number of digits, and $ is the end sign, indicating that it ends with a number!
OK, now that we can implement the pseudo static page, write down the rules:
Copy Code code as follows:
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^index.html$ index.php
Rewriterule ^new-(\d+). html$ newxx.php?uid=$1
</IfModule>
We can realize http://127.0.0.1/index.html and http://127.0.0.1/new-1.html.