Simple Application Example of apache pseudo-static page

Source: Internet
Author: User

Simple Application Example of apache pseudo-static page
We need the apache mod_rewrite module for pseudo-static in apache. The processing method is RewriteEngine on # rewriteengine in the apache configuration file. The RewriteEngine is the rewrite engine switch on and off to disable.


Create a. htaccess File
(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.

1. Check whether Apache supports mod_rewrite.
Use the phpinfo () function provided in the php tutorial to view the environment configuration. use Ctrl + F to find "Loaded Modules", which lists all Modules enabled by apache2handler, if "mod_rewrite" is included, it is supported and you do not need to set it again. 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.

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 (%a-za-z%}1,%}-(%0-9%}1,%}.html $ index. php? Action = $1 & id = $2

([A-za-z000000001, 00000000-(%0-9000000001, 00000000.html $ is the rule, index. php? Action = $1 & id = $2 is the format to be replaced. $1 indicates the matching value of the first parenthesis, $2 indicates the second, and so on !!

 

In the browser, enter:
Localhost/view-12.html

<? Php

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

Echo '<br/> ';

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

?>

 

The output is:
Your Action is: view
Your ID is: 12

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.