APACHE for PHP pseudo-static Rewrite settings, rewriteapache_PHP tutorial

Source: Internet
Author: User
APACHE for PHP pseudo-static Rewrite settings, rewriteapache. APACHE for PHP pseudo-static Rewrite settings. rewriteapache 1. Apache configuration: 1. support for httpd. conf configuration 2. supports directories. htaccess configuration (APACHE for virtual empty PHP pseudo-static Rewrite settings in a distributed configuration file, rewriteapache)

1. Apache configuration:

1. support httpd. conf configuration
2. supports directory. htaccess configuration (a "distributed configuration" file is intended for virtual spaces, and the space provider does not allow Apache configuration files to be modified)

Enable Rewrite (httpd. conf)
(Sometimes Options Indexes FollowSymLinks has a problem. you only need to configure Options all)

LoadModule rewrite_module modules/mod_rewrite.so


Enable. htaccess
AllowOverride None: AllowOverride All

II. mod_rewrite rules:
For example:

RewriteEngine on-> start rewrite engine RewriteRule ^/test ([0-9] * mongo.html $/test. php? Id = $1-> testplus any field .html can jump to the test. php regex matching field stored in virtual memory matching $1


3. mod_rewrite rule modifier

1) R forces external redirection
2) F disables the URL and returns the 403HTTP status code.
3) if G forces the URL to be GONE, the response HTTP status code is returned.
4) P enforces proxy forwarding.
5) L indicates that the current rule is the last rule, and the rule is overwritten after analysis is stopped.
6) N re-run the rewrite process from the first rule.
7) C. associate with the next rule

If the rule matches, it is processed normally. the following modifier is invalid.

8) T = MIME-type (force MIME type) force MIME type
9) NS is only used for non-internal subrequests
10) the NC is case insensitive.
11) QSA append request string
12) NE does not output escape special characters \ % 3d $1 is equivalent to = $1


For example:

RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]



Simple example:

RewriteEngine onRewriteRule ^/in(.*).html$ /index.php


PHP + Apache: pseudo-static configuration

Create a file such as. htaccess in the root directory of the website.
Then you can write pseudo-static UEL rules.
RewriteEngine On
RewriteRule ^ (. *) content-([0-9] +)-([0-9] +)-([0-9] + )\. html $1/index \. php \? M = content & c = index & a = show & catid = $2 & id = $3 & page = $4
RewriteRule ^ (. * When show-(%0-9then 00000000-(%0-9then 00000000-(%0-9then 000000000000.html $1/index \. php \? M = content & c = index & a = show & catid = $2 & id = $3 & page = $4
RewriteRule ^ (. * javaslist-(%0-9%%*-(%0-9%%%%%%%.html $1/index \. php \? M = content & c = index & a = lists & catid = $2 & page = $3

This completes the configuration.
PS: pseudo-static URL rules can be found online



Apache pseudo-static configuration

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

2. enable the apache server to support. htaccess
Modify the httpd. conf file

Options FollowSymLinks
AllowOverride None
Change
Options FollowSymLinks
AllowOverride All

Note: in addition to setting the above information, you have to set the lower part of the token (this section is not mentioned in many materials on the Internet). Otherwise, the configuration will fail, change the parameter after DocumentRoot to the directory of your local website. for example, if the root directory of your website is D:/web/, you must set it to DocumentRoot "D:/web/", that is, modify the current directory.

After this step is set, restart the apache server to take effect.

3. create a. htaccess file
Create htaccess.txt
Open it in Notepad, click "save as", enter ". htaccess" in the file name window, and click "save. This file must be saved to the root directory of the website.

4. enter pseudo-static website rules (regular expressions are required)



RewriteEngine on

RewriteRule index.html $ index. php
RewriteRule index-([1-9] + [0-9] * 2.16.html $ index. php? P = $1

</IfModule>

I hope to help you and other online friends, and I have been racking my brains.

Example 1: Apache configuration: 1. support for httpd. conf configuration 2. support for directory. htaccess configuration (a "distributed configuration" file is for virtual null...

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.