Configure pseudo-static for php in Linux, and PHP pseudo-static _ php Tutorial

Source: Internet
Author: User
Configure pseudo-static for php in Linux and pseudo-static for linuxphp. In Linux, configure pseudo-static for php. php pseudo-static mod_rewrite is a very powerful feature of Apache, which can implement pseudo-static pages. The following describes how to use it in detail. 1. check that php is configured with pseudo-static and linuxphp pseudo-static in Linux.

Mod_rewrite is a very powerful feature of Apache, which can implement pseudo-static pages. The following describes how to use it.

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 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. 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 ),
Open it in a text editor and find

The code is as follows:


Options FollowSymLinks
AllowOverride None

Change

The code is as follows:


Options FollowSymLinks
AllowOverride All

You can.
3. create a. htaccess file
There is one of the simplest ways to create a. htaccess file:
Open it in Notepad, click "save as", and enter ". htaccess" in the file name window. Note that the entire green part is used,
That is, it contains quotation marks, and then click save.
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 and supports regular expressions. the above ([0-9] {1,}) refers
It is an ending sign, indicating that it ends with a number! Okay, now we can implement pseudo-static pages. write down the rule: rewriteengineonrewriterule(%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 represents
A matching value in parentheses. 2 indicates the second one. so on !! Let's write a PHP script for processing: index. phpPHP 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

++ ++

Check that the httpd. conf of apache does not have the LoadModule rewrite_module modules/mod_rewrite.so line. you need to manually generate this module as follows:

Apache source package path:/ftp/httpd2.2

Apache installation path:/usr/local/apache/

I. added the mod_rewrite module.

The code is as follows:


# Find.-name mod_rewrite.c // find the mod_rewrite.c file in the apache source code installation directory
./Modules/mappers/mod_rewrite.c
# Cd/ftp/httpd2.2/modules/mappers // enter the directory containing the mod_rewrite.c file
#/Usr/local/apache/bin/apxs-c mod_rewrite.c // apxs should specify the absolute path, in the bin directory where you are currently using apache
#/Usr/local/apache/bin/apxs-I-a-n mod_rewrite mod_rewrite.la

If there are no errors, compile a mod_rewrite.so file in your apache modules Directory (/usr/local/apache/modules.

Edit the httpd. conf file and confirm that the httpd. conf file contains the loading statement mod_rewrite.so, as shown below:

LoadModule mod_rewrite_module modules/mod_rewrite.so

II. restart apache

1. if the following error occurs:

Httpd: Syntax error on line 54 of/usr/local/apache/conf/httpd. conf: Can't locate API module structure 'mod _ rewrite_module 'in file/usr/local/apache/modules/mod_rewrite.so: undefined symbol: mod_rewrite_module

You need

LoadModule mod_rewrite_module modules/mod_rewrite.so

Change

LoadModule rewrite_module modules/mod_rewrite.so

2. if the following error occurs:

Httpd: Syntax error on line 54 of/usr/local/apache/conf/httpd. conf: module rewrite_module is built-in and can't be loaded

Indicates that the module is built-in. you do not need to call it again and comment it out.

# LoadModule rewrite_module modules/mod_rewrite.so

3. enable url rewriting for a virtual site

1, edit the httpd-vhost.conf, add in the corresponding site label:

The code is as follows:


Directory/website/webA
AllowOverride All
/Directory

That is:

The code is as follows:


VirtualHost *: 80
DocumentRoot/website/webA
ErrorLog logs/webA.com-error_log
CustomLog logs/webA.com-access_log common
Directory/website/webA
AllowOverride All
/Directory
/VirtualHost

4. Save the rewrite rules for the site to the root directory of the site. the file name is ". htaccess"

5. restart apache.

Mod_rewrite is a very powerful feature of Apache, which can implement pseudo-static pages. The following describes how to use it in detail. 1. detection...

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.