Home > Article > Backend Development > PHP pseudo-static APACHE_PHP tutorial
1. Check whether Apache supports mod_rewrite
Check the environment configuration through the phpinfo() function provided by php, and find "Loaded Modules" through Ctrl+F, which lists all modules that apache2handler has opened. If it includes "mod_rewrite" is already supported and no further settings are needed.
If "mod_rewrite" is not turned on, open the httpd.conf file under your apache installation directory "/apache/conf/", use Ctrl+F to find "LoadModule rewrite_module", and change the "#" sign in front Just delete it.
If it is not found, go to the "LoadModule" area, add "LoadModule rewrite_module modules/mod_rewrite.so" in the last line (required to be an exclusive line), and then restart the apache server.
2. Let the apache server support .htaccess
How to make your local APACHE server support ".htaccess"? In fact, you can make APACHE support .htaccess by simply modifying apache's httpd.conf settings. Open the httpd.conf file (where is it? In the CONF directory of the APACHE directory), open it with a text editor and search for
changed to
That’s it.
3. Create .htaccess file
If you are on the Windows platform, I really don’t know how to create the “.htaccess” file at first, because this file actually has no file name, just an extension. This file cannot be created through ordinary methods, so don’t worry. , I will tell you three methods right away: All three methods first create a text file of htaccess.txt (of course, you can choose the name of this text file as you like), and then there are three ways to rename this file:
(1) Open it with Notepad, click File – Save As, enter ".htaccess" in the file name window, pay attention to the entire green part, which includes English quotes, and then click Save.
(2) Enter the cmd command window, use cd to switch the folder where the htaccess.txt file was just created, then enter the command: rename htaccess.txt .htaccess, and then click the Enter key on the keyboard.
(3) Connect the folder where htaccess.txt is located through ftp, and rename it through ftp software.
4.rewrite rule learning
After we create a new .htaccess file, write the following content in it:
Let me explain RewriteRule: RewriteRule is a rewriting rule that supports regular expressions. The above ([0-9]{1,}) refers to the number, and $ is the end mark, indicating that it ends with a number. !
Okay, now we can implement pseudo-static pages, write down the following rules:
You can achieve http://127.0.0.1/index.html and http://127.0.0.1/new-1.html