Php pseudo-static (urlrewritemod_rewrite rewrite) _ PHP Tutorial

Source: Internet
Author: User
Php pseudo-static (urlrewritemod_rewrite rewrite ). Mod_rewrite is a very powerful feature of Apache, which can implement pseudo-static pages. The following describes how to use it in detail! Useful for beginners! 1. Check If Apache supports mod_rewrite. it is a very powerful feature of Apache and can implement pseudo-static pages. The following describes how to use it in detail! Useful for beginners!
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 enable APACHE to support. htaccess. Open the httpd. conf file (where? In the CONF Directory of the APACHE Directory.

Options FollowSymLinks

AllowOverride None

Change

Options FollowSymLinks

AllowOverride All

You can.

3. create a. htaccess file

If it is on a windows platform, I don't know how to create it at the beginning ". "htaccess" file, because this file does not actually have a file name and only has a file extension. you cannot create this file in a common way. Don't worry. I will tell you three methods right away: you can create an htaccess.txt text file first (of course, the name of the text file can be retrieved as needed) in the three types of scripts. then, you can rename the file in three ways:

(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 into index.html $ index. php
RewriteRule ^ new-(\ d1_0000.html $ newxx. php? Uid = $1
Http: // 127.0.0.1/index.html and http: // 127.0.0.1/new-1.html

Bytes. The following describes how to use it in detail! Useful for beginners! 1. check whether Apache supports...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.