Table of Contents
PHP伪静态Rewrite设置之APACHE篇,rewriteapache
PHP+Apache配置伪静态的问题
apache 伪静态 配置
Home Backend Development PHP Tutorial PHP pseudo-static Rewrite settings for APACHE, rewriteapache_PHP tutorial

PHP pseudo-static Rewrite settings for APACHE, rewriteapache_PHP tutorial

Jul 13, 2016 am 10:21 AM
apache rewrite Pseudo-static

PHP伪静态Rewrite设置之APACHE篇,rewriteapache

 一、Apache配置:
 
1、支持httpd.conf 配置
2、支持目录 .htaccess配置(一种"分布式配置"文件针对虚拟空间,空间商不让修改Apache配置文件)
 
启用Rewrite(httpd.conf)
(有时候Options Indexes FollowSymLinks会出问题,只需要配置Options all即可)

LoadModule rewrite_module modules/mod_rewrite.so
Copy after login


启用.htaccess
AllowOverride None 修改为:AllowOverride All

二、mod_rewrite 规则:
例如:

RewriteEngine on              ->启动rewrite引擎
 
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1    ->指访问test加任意字段.html都能跳转到test.php    正则匹配的字段存放在虚拟内存匹配$1
Copy after login


三、mod_rewrite规则修正符

1) R 强制外部重定向
2) F 禁用URL,返回403HTTP状态码。
3) G 强制URL为GONE,返回410HTTP状态码。
4) P 强制使用代理转发。
5) L 表明当前规则是最后一条规则,停止分析以后规则的重写。
6) N 重新从第一条规则开始运行重写过程。
7) C 与下一条规则关联

如果规则匹配则正常处理,以下修正符无效

8) T=MIME-type(force MIME type) 强制MIME类型
9) NS 只用于不是内部子请求
10) NC 不区分大小写
11) QSA 追加请求字符串
12) NE 不在输出转义特殊字符 \%3d$1 等价于 =$1


例如:

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



简单小范例:

RewriteEngine on
RewriteRule ^/in(.*).html$ /index.php
Copy after login

PHP+Apache配置伪静态的问题

在网站的根目录创建一个.htaccess这样的文件
然后你写上伪静态的UEL规则
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 ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=$3&page=$4
RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3

这样就配置完成了
PS:伪静态的URL规则可以在网上找的

PHP pseudo-static Rewrite settings for APACHE, rewriteapache_PHP tutorial
 

apache 伪静态 配置

1. Check whether Apache supports mod_rewrite. View the environment configuration through the phpinfo() function provided by php. Use Ctrl+F to find "Loaded Modules", which lists all modules that apache2handler has opened. If it includes "mod_rewrite" , it is already supported and no further settings are required.
If "mod_rewrite" is not turned on, open the httpd.conf file under your apache installation directory "/apache/conf/", use Ctrl+F to find "LoadModule rewrite_module", and change the "#" sign in front Just delete it.
If it is not found, go to the "LoadModule" area, add "LoadModule rewrite_module modules/mod_rewrite.so" in the last line (required to be an exclusive line), and then restart the apache server.

2. Let the apache server support .htaccess
Modify the httpd.conf file

Options FollowSymLinks
AllowOverride None
Change to
Options FollowSymLinks
AllowOverride All

Note: In addition to setting the above place, you also need to set the following (a lot of information on the Internet does not mention this), otherwise you will fail to configure. Change the parameters behind DocumentRoot to your local The directory of the website. For example, if the root directory of your website is D:/web/, it must be set to DocumentRoot "D:/web/", which means modifying the current directory

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

3. Create a .htaccess file
Create a new htaccess.txt
Open it with Notepad, click File – Save As, enter ".htaccess" in the file name window, and then click Save. This file must be saved in the root directory of the website

4. Fill in the pseudo-static rules of the website (need to know regular expressions)



RewriteEngine on

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



I hope it can help you and other friends on the Internet. I also racked my brains on it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/854359.htmlTechArticlePHP pseudo-static Rewrite settings APACHE, rewriteapache 1. Apache configuration: 1. Support httpd.conf configuration 2. Support directory .htaccess configuration (a "distributed configuration" file for virtual spaces...
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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 Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency PHP Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency Apr 30, 2024 pm 12:27 PM

According to benchmarks, Laravel excels in page loading speed and database queries, while CodeIgniter excels in data processing. When choosing a PHP framework, you should consider application size, traffic patterns, and development team skills.

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

How to add a server in eclipse How to add a server in eclipse May 05, 2024 pm 07:27 PM

To add a server to Eclipse, follow these steps: Create a server runtime environment Configure the server Create a server instance Select the server runtime environment Configure the server instance Start the server deployment project

The evasive module protects your website from application layer DOS attacks The evasive module protects your website from application layer DOS attacks Apr 30, 2024 pm 05:34 PM

There are a variety of attack methods that can take a website offline, and the more complex methods involve technical knowledge of databases and programming. A simpler method is called a "DenialOfService" (DOS) attack. The name of this attack method comes from its intention: to cause normal service requests from ordinary customers or website visitors to be denied. Generally speaking, there are two forms of DOS attacks: the third and fourth layers of the OSI model, that is, the network layer attack. The seventh layer of the OSI model, that is, the application layer attack. The first type of DOS attack - the network layer, occurs when a large number of of junk traffic flows to the web server. When spam traffic exceeds the network's ability to handle it, the website goes down. The second type of DOS attack is at the application layer and uses combined

Application of algorithms in the construction of 58 portrait platform Application of algorithms in the construction of 58 portrait platform May 09, 2024 am 09:01 AM

1. Background of the Construction of 58 Portraits Platform First of all, I would like to share with you the background of the construction of the 58 Portrait Platform. 1. The traditional thinking of the traditional profiling platform is no longer enough. Building a user profiling platform relies on data warehouse modeling capabilities to integrate data from multiple business lines to build accurate user portraits; it also requires data mining to understand user behavior, interests and needs, and provide algorithms. side capabilities; finally, it also needs to have data platform capabilities to efficiently store, query and share user profile data and provide profile services. The main difference between a self-built business profiling platform and a middle-office profiling platform is that the self-built profiling platform serves a single business line and can be customized on demand; the mid-office platform serves multiple business lines, has complex modeling, and provides more general capabilities. 2.58 User portraits of the background of Zhongtai portrait construction

How to deploy and maintain a website using PHP How to deploy and maintain a website using PHP May 03, 2024 am 08:54 AM

To successfully deploy and maintain a PHP website, you need to perform the following steps: Select a web server (such as Apache or Nginx) Install PHP Create a database and connect PHP Upload code to the server Set up domain name and DNS Monitoring website maintenance steps include updating PHP and web servers, and backing up the website , monitor error logs and update content.

How to implement PHP security best practices How to implement PHP security best practices May 05, 2024 am 10:51 AM

How to Implement PHP Security Best Practices PHP is one of the most popular backend web programming languages ​​used for creating dynamic and interactive websites. However, PHP code can be vulnerable to various security vulnerabilities. Implementing security best practices is critical to protecting your web applications from these threats. Input validation Input validation is a critical first step in validating user input and preventing malicious input such as SQL injection. PHP provides a variety of input validation functions, such as filter_var() and preg_match(). Example: $username=filter_var($_POST['username'],FILTER_SANIT

How to leverage Kubernetes Operator simplifiy PHP cloud deployment? How to leverage Kubernetes Operator simplifiy PHP cloud deployment? May 06, 2024 pm 04:51 PM

KubernetesOperator simplifies PHP cloud deployment by following these steps: Install PHPOperator to interact with the Kubernetes cluster. Deploy the PHP application, declare the image and port. Manage the application using commands such as getting, describing, and viewing logs.

See all articles