PHP pseudo-static APACHE_PHP tutorial

WBOY
Release: 2016-07-13 10:29:06
Original
723 people have browsed it

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

Copy code The code is as follows:

Options FollowSymLinks
AllowOverride None

changed to

Copy code The code is as follows:

Options FollowSymLinks
AllowOverride All

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:

Copy code The code is as follows:

RewriteEngine on #rewriteengine is the rewrite engine switch on is on and off is off
RewriteRule ([0-9]{1,})$ index.php?id=$1

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:

Copy code The code is as follows:


RewriteEngine On
RewriteRule ^index .html$ index.php
RewriteRule ^new-(d+).html$ newxx.php?uid=$1

You can achieve http://127.0.0.1/index.html and http://127.0.0.1/new-1.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/779161.htmlTechArticle1. Check whether Apache supports mod_rewrite. View the environment configuration through the phpinfo() function provided by php and search through Ctrl+F Go to "Loaded Modules", which lists all apache2handlers that have been enabled...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!