PHP pseudo-static (URL rewrite mod_rewrite rewrite) _php tutorial

Source: Internet
Author: User
Tags ftp connection
Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages. Let me tell you more about how to use it! Very useful for beginners Oh!
1. Detect if Apache supports Mod_rewrite
Using PHP's Phpinfo () function to view the environment configuration, through Ctrl+f find to "Loaded Modules", which lists all the Apache2handler has been opened module, if it includes "mod_rewrite", it is already supported, You no longer need to continue setup.

If "Mod_rewrite" is not turned on, open the directory under your Apache installation directory "/apache/conf/" under the httpd.conf file, through ctrl+f find to "LoadModule Rewrite_module", the previous " # "number to delete.
If not found, go to the "LoadModule" area, add "LoadModule rewrite_module modules/mod_rewrite.so" (Required exclusive line) to the last line, and then restart the Apache server.

2. Let Apache server support. htaccess

How do I get my local Apache server to support the ". htaccess"? In fact, simply modify the Apache httpd.conf settings to allow Apache support. htaccess. Open a. httpd.conf file (where?) In the Conf directory of the Apache directory), when opened with a text editor, find

Options FollowSymLinks

AllowOverride None

Switch

Options FollowSymLinks

AllowOverride All

You can do it.

3. Create a. htaccess file

If it is under the Windows platform, I really do not know how to create a ". htaccess" file, because this file does not actually have a filename, only the extension, through the normal way is unable to build this file, don't worry, I'll tell you right away. Three ways: Three methods are to create a htaccess.txt text file (of course, the name of the text file you can take any), and then there are three ways to rename the file:

(1) Open with Notepad, click on the file – Save As, enter ". htaccess" in the File name window, note that the whole green section, that is, contains the quotation marks, then click on Save on the line.

(2) Go to cmd Command window, switch to the folder of the Htaccess.txt file by CD, then enter the command: Rename Htaccess.txt. htaccess, then click the keyboard enter key.

(3) through the FTP connection Htaccess.txt folder, through the FTP software rename.

4.rewrite Rule Learning

After we create a new. htaccess file, we write the following in it:

Rewriteengine on #rewriteengine为重写引擎开关on为开启off为关闭

Rewriterule ([0-9]{1,}) $ index.php?id=$1

Let me explain. Rewriterule:rewriterule is a rewrite rule that supports regular expressions, the above ([0-9]{1,}) refers to numbers, $ is the end flag, and the description is the end of the number!

OK, now we can implement pseudo-static page, write down the following rules:


Rewriteengine on
Rewriterule ^index.html$ index.php
Rewriterule ^new-(\d+). html$ newxx.php?uid=$1
We can achieve http://127.0.0.1/index.html and http://127.0.0.1/new-1.html.

http://www.bkjia.com/PHPjc/778216.html www.bkjia.com true http://www.bkjia.com/PHPjc/778216.html techarticle Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages. Let me tell you more about how to use it! Very useful for beginners Oh! 1. Check whether Apache is supported ...

  • Related Article

    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.