1. Detect if Apache is turning on mod_rewrite function
The Phpinfo () function provided by PHP can be used to view the environment configuration and find "Loaded Modules", which lists all the modules that have been opened by Apache2handler, and if it includes "mod_rewrite", it is already supported and no longer required to continue setting.
If "Mod_rewrite" is not turned on, open the directory Apache directory "/apache/conf/", find the httpd.conf file, and then find "LoadModule rewrite_module", the Front "#" This feature is used when the number is deleted.
If you do not find the "LoadModule" area, you can add "LoadModule rewrite_module, modules/mod_rewrite.so" (exclusive row) on the last line, and then restart the Apache server. The Phpinfo () function then looks at the environment configuration with "Mod_rewrite" as the item.
2. Let Apache server support. htaccess How to make your local Apache server support: "Htaccess"? Just modify Apache's httpd.conf settings to allow Apache to support ". htaccess".
Open the httpd.conf file in the Conf directory of the Apache directory, find: Options followsymlinks allowoverride None change to Options FollowSymLinks allowoverride All on the line.
3. When establishing the. htaccess file, be aware that the. htaccess file cannot be built directly by using the Save As menu in Notepad, enter: ". htaccess" in the File name window, then click Save.
4.rewrite Rule Learning
After the new. htaccess file is created, it is written in the following: Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭 rewriterule ([0-9]{1,}) $index. php?id =$1 here, Rewriterule is the rewrite rule, is a regular expression of the sentence, ([0-9]{1,}) is composed of numbers, $ represents the end of the flag, indicating the end of the number!
If you want to implement a pseudo-static page, the rule is as follows: Rewriteengine on Rewriterule ([A-za-z]{1,})-([0-9]{1,}). html$index.php?action=$1&id=$2 In a regular expression, ([A-za-z]{1,})-([0-9]{1,}). html$ is the rule, the index.php?action=$1&id=$2 is the format to be replaced, the value that represents the 1th bracket match, and the value of the second parenthesis. So analogy!
Test the PHP script as follows: The code in the index.php file is as follows: Echo ' Your Action value is: '. $_get[' action ']; Echo '; The echo ' ID value is: '. $_get[' id '];?>
In the browser address bar input: localhost/page-18.html output is: Your Action value is: Page ID value is: 18
Oh, rewrite success!
Article Source: http://jingyan.baidu.com/article/624e7459aa58e434e8ba5ac2.html
PHP open pseudo-static configuration