Php pseudo-static method

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. check whether Apache supports mod_rewrite. Use the phpinfo () function provided by php to view the environment configuration. use Ctrl + F to find LoadedModules. All modules enabled by apache2handler are listed. If mod_rewrite is included, the

Welcome to the Linux community forum and interact with 2 million technical staff> enter 1. check whether Apache supports mod_rewrite. Use the phpinfo () function provided by php to view the environment configuration. use Ctrl + F to find "Loaded Modules", which lists all Modules enabled by apache2handler, if "mod_rewrite" is included

Welcome to the Linux community forum and interact with 2 million technicians>

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 ", this parameter is supported and does not need to be set.

If "mod_rewrite" is not enabled, open httpd under your apache installation directory "/apache/conf. in the conf file, use Ctrl + F to find "LoadModule rewrite_module" and delete the previous.

If no result is found, add "LoadModule rewrite_module, modules/mod_rewrite.so" to the last row in the "LoadModule" area, and then restart the apache server.

2. Support apache servers. 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 support APACHE. Htaccess. Open the httpd. conf file (where? In the CONF directory of the APACHE directory ),

Open it in a text editor and find

Options FollowSymLinks

AllowOverride None

Change

Options FollowSymLinks

AllowOverride All

You can.

3. Create. Htaccess File

There is one of the simplest ways to establish. Htaccess file:

Open it in notepad and click the file? Save as, enter ". htaccess" in the file name window, note that it is the entire Green part,

That is, it contains quotation marks, and then click Save.

4. rewrite rule learning

Create a new one. Write the following content into the htaccess file:

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 and supports regular expressions. The above ([0-9] {1,}) refers

It is composed of words. $ indicates the end sign, indicating that the end is 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

A matching value in parentheses. $2 represents the second one, and so on !!

Let's write a PHP script for processing:

Index. php

PHP code

Echo 'your Action is: '. $ _ GET ['action'];

Echo'

';

Echo 'your ID is: '. $ _ GET ['id'];

?>

Now, in the browser, enter:

Localhost/page-18.html

The output is:

Your Action is: page

Your ID is: 18

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.