1. Check whether Apache supports mod_rewrite.
Use the phpinfo () function provided by PHP to view the environment configuration, and use Ctrl + F to find "loaded modules", which lists all modules enabled by apache2handler. If "mod_rewrite" is included ", this parameter is supported and does not need to be set.
If "mod_rewrite" is not enabled, open httpd in the directory of your Apache installation directory "/Apache/CONF. in the conf file, use Ctrl + F to find "loadmodule rewrite_module" and delete.
If not found, add "loadmodule rewrite_module modules/mod_rewrite.so" to the last row in the "loadmodule" area, and then restart the Apache server.
2. Enable the Apache server to support. htaccess
How can I enable my local Apache server to support ". htaccess? In fact, you only need to modify the httpd. conf settings of Apache to make
Apache supports. htaccess. Open the httpd. conf file (where? In the conf directory of the Apache directory.
<Directory/>
Options followsymlinks
AllowOverrideNone
</Directory>
Change
<Directory/>
Options followsymlinks
AllowOverrideAll
</Directory>
You can.
3. Create a. htaccess File
If it is on the Windows platform, I really don't know how to create a ". htaccess" file at the beginning, because this file actually has no file name, only the extension
You cannot create this file. Don't worry. You can immediately tell you three methods:
And there are three ways to rename the file:
(1) Open it in notepad, click "Save as", and enter ". htaccess" in the file name window. Note that the entire Green section contains English quotation marks, and click "save.
(2) Go to the CMD command window, switch to the folder where the htaccess.txt file is just created, enter the command: Rename htaccess.txt. htaccess, and then click Enter.
(32.16connect to the folder where htaccess.txt is located through ftpand rename it through FTP software.
4. Rewrite rule learning
After creating a new. htaccess file, we will write the following content into it:
Rewriteengine on # rewriteengine is the rewrite engine switch on is to turn off
Rewriterule ([0-9] {1,}) $ index. php? Id = $1
Rewriterule: rewriterule is a rewrite rule that supports regular expressions. The above ([0-9] {1,}) is composed of numbers, and $ is the end sign, the description ends with a number!
Now we can implement pseudo-static pages. Write down the rules below:
Rewriteengine on
Rewriterule ([A-Za-Z] {1,})-([0-9] {1,})/. html $ index. php? Action = $1 & id = $2
([A-Za-Z] {1,})-([0-9] {1,})/. html $ is a rule, index. php? Action = $1 & id = $2 is the format to be replaced. $1 indicates the matching value of the first parenthesis, $2 indicates the second, and so on !!
Let's write a PHP script for processing:
Index. php
PHP code
- <? PHP
- Echo 'your action is: '. $ _ Get ['action'];
- Echo '<br/> ';
- Echo 'your ID is: '. $ _ Get ['id'];
- ?>
Now, in the browser, enter:
Localhost/view-12.html
The output is:
Your action is: View
Your ID is: 12