search
Homephp教程php手册PHP识别url重写请求

PHP识别url重写请求

Jun 06, 2016 pm 07:59 PM
phpurlNowprogramidentifyaskrewrite

现在很多PHP程序都使用了url重写技术来优化url,但是有时候我们要在PHP程序中区分默认url的请求和url重写后的请求,这该如何处理呢? 我的解决方案是在常量$_SERVER里面找答案,在不同的服务器中$_SERVER都会有一个索引用来记录重写请求访问重写之前的路径,

现在很多PHP程序都使用了url重写技术来优化url,但是有时候我们要在PHP程序中区分默认url的请求和url重写后的请求,这该如何处理呢?

我的解决方案是在常量$_SERVER里面找答案,在不同的服务器中$_SERVER都会有一个索引用来记录重写请求访问重写之前的路径,部分主流服务器的索引如下

IIS7 + Rewrite Module -> $_SERVER['HTTP_X_ORIGINAL_URL']

IIS6 + ISAPI Rewite -> $_SERVER['HTTP_X_REWRITE_URL’]

Apache2 -> $_SERVER['REQUEST_URI’] 或 $_SERVER['REDIRECT_URL']

nginx -> $_SERVER['REQUEST_URI’]

因此得出的结果是,只要判断 HTTP_X_ORIGINAL_URL, HTTP_X_REWRITE_URL, REQUEST_URI, REDIRECT_URL 这些参数,我们就可以在PHP中来判断请求url来自于重写地址的还是默认格式的地址了。

 

注:关于url重写

Statement
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software