Steps to implement pseudo-static in PHP

Source: Internet
Author: User
How to implement pseudo-static in PHP
How to implement pseudo-static in PHP

Mod_rewrite is a very powerful feature of Apache that can implement pseudo-static pages. Let me tell you more about how it's used.

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 row) in 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?) Conf directory in 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

There are 1 easiest ways to build. htaccess files:

Open with Notepad, click File – Save As, enter ". htaccess" in the File name window, notice the whole green section,

That is, include the quotation marks, and then click Save on the line.

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, above ([0-9]{1,}) refers to the number of

The word composition, $ is the end of the flag, the description is ending with a number!

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

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 the rule, and index.php?action=$1&id=$2 is the format to be replaced, representing the first

A pair of parentheses matches the value, which is the second one, so to speak!!

We write a PHP script for processing:

index.php

PHP code

Echo ' Your action is: '. $_get[' action '];

Echo '

’;

Echo ' Your ID is: '. $_get[' id '];

?>

OK, now we're typing in the browser:

Localhost/page-18.html

The output is:

Your action is: page

Your ID is: 18

Original address: http://www.software8.co/wzjs/PHPshili/896.html

  • 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.