Home Backend Development PHP Tutorial Detailed introduction to RewriteCond rule parameters in Apache_PHP tutorial

Detailed introduction to RewriteCond rule parameters in Apache_PHP tutorial

Jul 20, 2016 am 11:16 AM
apache rewritecond introduce parameter right of rule detailed statement

The RewriteCond statement in Apache has always been a difficult point for me. I have tried to understand it many times, but there is no structure. This time I finally know roughly what it means. ​

RewriteCond is just like the if statement in our program. It means that if one or several conditions are met, the RewriteRule statement immediately below RewriteCond will be executed. This is the most original and basic function of RewriteCond. To facilitate understanding, let’s look at it below Let’s look at a few examples.

Copy code The code is as follows:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Mozilla//5/.0.*
RewriteRule index.php index.m.php
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule index.php index.L.php
RewriteRule index.php index.b.php


The function of the above statement is that when you use the FF browser to access the index.php file, it will automatically allow you to access the index.m.php file. When you use some mobile terminals to access it, it will allow you to access it. When accessing the index.php file, you actually access index.L.php. If you access it using another browser, you will be redirected to index.b.php. Speaking more vividly, the above statement is equivalent to the following statement in the program (take the PHP statement as an example):

Copy code The code is as follows:
if($_SERVER['HTTP_USER_AGENT'] == 'Mozilla/5.0')
{
//Jump to access to index.m.php
}
else if($_SERVER['HTTP_USER_AGENT'] == 'Lynx')
{
//Jump to access to index.L.php
}
else
//Jump to access to index.b.php


Looking at Example 2:
RewriteCond %{HTTP_REFERER} (www.test.cn)
RewriteRule (.*)$ test.php
The function of the above statement is that if the host address of the previous page you visited is www.test.cn, no matter which page you are currently visiting, you will jump to access test.php.
Looking at Example 3:

Copy code The code is as follows:
RewriteCond %{REMOTE_HOST} ^host1.* [OR]
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
RewriteCond %{REMOTE_HOST} ^host3.*
RewriteRule (.*)$ test.php


The function of the above statement is that if your address is host1 or host2 or host3, it will jump to test.php. It can be seen from here that the default between RewriteCond statements is AND. If you want OR, you must write it explicitly.
Here are some useful rewriting rules that you have collected:
RewriteCond %{REQUEST_FILENAME} !-f //If the file exists, access the file directly without performing the following RewriteRule. (If the file does not exist or the file does not exist, rewrite will be performed)
RewriteCond %{REQUEST_FILENAME} !-d //#If the directory exists, access the directory directly without performing RewriteRule
RewriteCond %{REQUEST_URI} !^.*(/.css|/.js|/.gif|/.png|/.jpg|/.jpeg)$ //#If it is a file with these suffixes, access the file directly. No Rewrite

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/372370.htmlTechArticleThe RewriteCond statement in Apache has always been a difficulty for me. I have tried to figure it out many times, but there is no structure. , this time I finally know roughly what it means. RewriteCond is just like us...
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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 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)

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.

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

Detailed introduction of Samsung S24ai functions Detailed introduction of Samsung S24ai functions Jun 24, 2024 am 11:18 AM

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

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

Rules and exceptions for pointer comparisons? Rules and exceptions for pointer comparisons? Jun 04, 2024 pm 06:01 PM

In C/C++, the pointer comparison rules are as follows: pointers pointing to the same object are equal. Pointers to different objects are not equal. Exception: Pointers to null addresses are equal.

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

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

See all articles