Home Backend Development PHP Tutorial Pseudo-static configuration and usage in apache

Pseudo-static configuration and usage in apache

Jul 29, 2016 am 09:02 AM
apache php rewrite

1 Open Apache’s configuration file httpd.conf.
Second, remove the # in front of #LoadModule rewrite_module modules/mod_rewrite
Third, add in httpd.conf:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{ENV:SCRIPT_URL} (?:index|dispbbs)[ -0-9]+.html
RewriteRule ^(.*?(?:index|dispbbs))-([-0-9]+).html$ $1.php?__is_apache_rewrite=1&__rewrite_arg=$2
</IfModule&gt ;

Fourth: To implement the mapping of asp post URL to php post, add between <IfModule mod_rewrite.c> and </IfModule> in the third step:
RewriteMap tolowercase int:tolower
RewriteCond %{QUERY_STRING} ( ?:boardid|page|id|replyid|star|skin)=d+ [NC]
RewriteRule ^(.*(?:index|dispbbs)).asp$ $1.php?${tolowercase:%{QUERY_STRING}}&__is_apache_rewrite =1

5 Save httpd.conf and restart Apache.

6. Introduction to mod_rewrite
The main function of Rewirte is to realize URL jump and hide the real address, based on the regular expression specification of Perl language. We usually help us achieve pseudo-static, pseudo-directory, domain name jump, prevent hot links, etc.
7. Use of mod_rewrite rules
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com [NC]
RewriteRule ^/( .*) http://www.php100.com/ [L]
--------
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id =$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]
8. mod_rewrite rule modifier
1) R forces external redirection
2) F disables URL, Returns 403 HTTP status code.
3) G forces the URL to be GONE and returns 410 HTTP status code.
4) P forces the use of proxy forwarding.
5) L indicates that the current rule is the last rule and stops analyzing the rewriting of future rules.
6) N Run the rewrite process starting from the first rule again.
7) C is associated with the next rule 8) T=MIME-type (force MIME type) forces MIME type
9) NS is only used for non-internal subrequests
10) NC is not case sensitive
11) QSA appends request characters String
12) NE does not output escaped special characters %3d$1 is equivalent to =$1

The above introduces the pseudo-static configuration and use in apache, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles