Apache Mod_rewrite is more powerful, in the site construction, you can use this module to achieve pseudo static.
The main steps are as follows:
1. Detect whether Apache open Mod_rewrite function can be provided by the PHP phpinfo () function to view the environment configuration, find "Loaded Modules", which lists all the Apache2handler have been open modules, if the inside includes " Mod_rewrite ", it is already supported and no longer needs to be set. If "Mod_rewrite" is not turned on, open the "/apache/conf/" in the Directory Apache directory, locate the httpd.conf file, and then find "LoadModule rewrite_module", which will be preceded by "#" The deletion of a number means that the feature is taken. If you do not find the "LoadModule" area, you can add "LoadModule rewrite_module, modules/mod_rewrite.so" (exclusive line) on the last line, and then restart the Apache server. The Phpinfo () function is used to view the environment configuration with the term "mod_rewrite".
2. Let Apache server support. htaccess how to get 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 to find: Options followsymlinks allowoverride None to Options FollowSymLinks allowoverride All on the line.
3. The establishment of. htaccess documents to establish. htaccess files should be noted that cannot be directly built, by using the Save As menu in Notepad, in the filename window enter: ". htaccess", and then click Save.
4.rewrite Rule Learning After you create a new. htaccess file, write the following: Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭 rewriterule ([0-9]{1,}) $index. php?id=$1 here, Rewriterule is an overriding rule, a sentence with a regular expression, ([0-9]{1,}) represented by a number, and $ for the end sign, which means ending with a number! If you want to implement a pseudo static page, the rules are 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, 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 bracket in $, So the 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 '; 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: 18
Oh, rewrite success!
Here are some personal experiences that I've configured for my own pseudo static to share:
Start contact pseudo Static, look very magical, think very difficult, in fact very simple, that is, in the server more than a few virtual domain names, similar to the real access to the Web site. Just three steps.
A. First in the Apache Apache module, open Vhost_alias_moudle
B. Modify the httpd.conf file, in this file, search rewrite. Find LoadModule rewrite_module modules/mod_rewrite.so remove the front #
C. Modify this file, D:\wamp\bin\apache\Apache2.2.21\conf\extra under the path of the httpd-vhosts.conf file, follow the example plus one is OK
Copy Code code as follows:
<virtualhost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "D:/wamp/www/dz"
ServerName localhost.www.dz.cn
ErrorLog "Logs/dummy-host2.example.com-error.log"
Customlog "Logs/dummy-host2.example.com-access.log" common
</VirtualHost>
D. Configure in the Hosts file under the path C:\Windows\System32\drivers\etc
127.0.0.1 localhost.www.dz.cn service can be restarted. Done!
Happy New Year to everyone!
Note: In the browser input localhost.www.dz.cn, you can access, I add a localhost is to and the official web site to distinguish. Have not understand can contact me, convenient for everyone to discuss together, progress together!
Your pseudo static rules are all written in the. htaccess file, and the file is loaded by default because pseudo static is turned on. Write this. htaccess file to write regular Oh, learn some regular basis!