|
Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages.
1, detect whether Apache support Mod_rewrite through the phpinfo () function provided by PHP to view the environment configuration, through Ctrl+f find "Loaded Modules", It lists all the modules that the Apache2handler has already opened, and if it includes "mod_rewrite", it is supported and no longer required to continue setting.
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 to "LoadModule Rewrite_module", the previous " # "number to delete. If not found, go to the "LoadModule" area, add "LoadModule rewrite_module modules/mod_rewrite.so" (Required exclusive line) to the last line, and then restart the Apache server.
2, let Apache server support. htaccess How to enable the local Apache server to support ". htaccess"? Modify Apache's httpd.conf settings to allow Apache support. htaccess.
Open a. httpd.conf file (where?) In the Conf directory of the Apache directory), when opened with a text editor, look for:
- Options FollowSymLinks
- AllowOverride All
Copy Code
You can do it.
3. Create a. htaccess file
If it is under the Windows platform, I really do not know how to create a ". htaccess" file, because this file does not actually have a filename, only the extension, through the normal way is unable to build this file, don't worry, I'll tell you right away. Three ways: Three methods are first to create a htaccess.txt text file (of course, the name of the text file you can randomly take), and then there are three ways to rename the file: 1), open with Notepad, click File – Save As, in the File name window, enter ". Htaccess ", note that the entire green section, that is, contains the English quotation marks, and then click Save on the line. 2), go to cmd Command window, switch to the folder by CD when the Htaccess.txt file is just established, then enter the command: Rename Htaccess.txt. htaccess, then click the keyboard enter key. 3), through the FTP connection Htaccess.txt folder, through the FTP software rename.
4,rewrite rules
Create a new. htaccess file that creates the content:
- Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭
- Rewriterule ([0-9]{1,}) $ index.php?id=$1
Copy Code
Rewriterule:rewriterule is a rewrite rule that supports regular expressions, the above ([0-9]{1,}) refers to numbers, $ is the end flag, and the description is the end of the number!
Implement pseudo-static pages, rules:
- Rewriteengine on
- Rewriterule ^index.html$ index.php
- Rewriterule ^new-(\d+). html$ newxx.php?uid=$1
Copy Code
Implement http://127.0.0.1/index.html and Http://127.0.0.1/new-1.html
|