Table of Contents
您可能感兴趣的文章
Home php教程 php手册 .htaccess 语法参数说明

.htaccess 语法参数说明

Jun 13, 2016 am 09:36 AM
parameter grammar illustrate

接触过 .htaccess 文件的朋友们是否对立面的一些语法不是很懂,经常会看到一条规则后面跟些大写的 L NC R QSA 什么的,知道他们什么意思吗?OK,下面这篇文章就是简单的对 .htaccess 文件的相关语法参数进行一下简单的说明。

chain|C(链接下一规则)

此标记使当前规则与下一个规则相链接。它产生这样的效果:如果一个规则被匹配,则继续处理其后继规则,也就是这个标记不起作用;如果该规则不被匹配,则其后继规则将被跳过。比如,在一个目录级规则中执行一个外部重定向时,你可能需要删除”.www”(此处不应该出现”.www”)。

cookie|CO=NAME:VAL:domain[:lifetime[:path]](设置cookie)

在客户端设置一个cookie。cookie的名称是NAME,值是VAL。domain是该cookie的域,比如.apache.org,可选的lifetime是cookie的有效期(分钟),可选的path是cookie的路径。

env|E=VAR:VAL(设置环境变量)

此标记将环境变量VAR的值为VAL,VAL可以包含可扩展的正则表达式反向引用($N和%N)。此标记可以多次使用以设置多个变量。这些变量可以在其后许多情况下被间接引用,通常是在XSSI()或CGI($ENV{VAR})中,也可以在后继的RewriteCond指令的CondPattern参数中通过%{ENV:VAR}引用。使用它可以记住从URL中剥离的信息。

forbidden|F(强制禁止URL)

强制禁止当前URL,也就是立即反馈一个HTTP响应码403(被禁止的)。使用这个标记,可以链接若干个RewriteConds来有条件地阻塞某些URL。

gone|G(强制废弃URL)

强制当前URL为已废弃,也就是立即反馈一个HTTP响应码410(已废弃的)。使用这个标记,可以标明页面已经被废弃而不存在了。

handler|H=Content-handler(强制指定内容处理器)

强自制定目标文件的内容处理器为Content-handler。例如,用来模拟mod_alias模块的ScriptAlias指令,以强制映射文件夹内的所有文件都由”cgi-script”处理器处理。

last|L(结尾规则)

立即停止重写操作,并不再应用其他重写规则。它对应于Perl中的last命令或C语言中的break命令。这个标记用于阻止当前已被重写的URL被后继规则再次重写。例如,使用它可以重写根路径的URL(/)为实际存在的URL(比如:/e/www/)。

next|N(从头再来)

重新执行重写操作(从第一个规则重新开始)。此时再次进行处理的URL已经不是原始的URL了,而是经最后一个重写规则处理过的URL。它对应于Perl中的next命令或C语言中的continue命令。此标记可以重新开始重写操作(立即回到循环的开头)。但是要小心,不要制造死循环!

nocase|NC(忽略大小写)

它使Pattern忽略大小写,也就是在Pattern与当前URL匹配时,A-Z和a-z没有区别。

noescape|NE(在输出中不对URI进行转义)

此标记阻止mod_rewrite对重写结果应用常规的URI转义规则。 一般情况下,特殊字符(%, $, ;等)会被转义为等值的十六进制编码(%25′, %24′, %3B等)。此标记可以阻止这样的转义,以允许百分号等符号出现在输出中,比如:

RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] 可以使/foo/zed转向到一个安全的请求/bar?arg=P1=zed

nosubreq|NS(不对内部子请求进行处理)

在当前请求是一个内部子请求时,此标记强制重写引擎跳过该重写规则。比如,在mod_include试图搜索目录默认文件(index.xxx)时,Apache会在内部产生子请求。对于子请求,重写规则不一定有用,而且如果整个规则集都起作用,它甚至可能会引发错误。所以,可以用这个标记来排除某些规则。使用原则:如果你为URL添加了CGI脚本前缀,以强制它们由CGI脚本处理,但对子请求处理的出错率(或者资源开销)很高,在这种情况下,可以使用这个标记。

proxy|P(强制为代理)

此标记使替换成分被内部地强制作为代理请求发送,并立即中断重写处理,然后把处理移交给mod_proxy模块。你必须确保此替换串是一个能够被mod_proxy处理的有效URI(比如以http://www.phpernote.com开头),否则将得到一个代理模块返回的错误。使用这个标记,可以把某些远程成分映射到本地服务器域名空间,从而增强了ProxyPass指令的功能。注意:要使用这个功能,必须已经启用了mod_proxy模块。

passthrough|PT(移交给下一个处理器)

此标记强制重写引擎将内部request_rec结构中的uri字段设置为filename字段的值,这个小小的修改使得RewriteRule指令的输出能够被(从URI转换到文件名的)Alias, ScriptAlias, Redirect等指令进行后续处理[原文:This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators.]。

举一个能说明其含义的例子: 如果要将/abc重写为/def, 然后再使用mod_alias将/def转换为/ghi,可以这样:

RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi

如果省略了PT标记,虽然将uri=/abc/…重写为filename=/def/…的部分运作正常,但是后续的mod_alias在试图将URI转换到文件名时会遭遇失效。注意:如果需要混合使用多个将URI转换到文件名的模块时,就必须使用这个标记。。此处混合使用mod_alias和mod_rewrite就是个典型的例子。

qsappend|QSA(追加查询字符串)

此标记强制重写引擎在已有的替换字符串中追加一个查询字符串,而不是简单的替换。如果需要通过重写规则在请求串中增加信息,就可以使用这个标记。

redirect|R [=code](强制重定向)

若Substitution以http://thishost[:thisport]/(使新的URL成为一个URI)开头,可以强制性执行一个外部重定向。如果没有指定code,则产生一个HTTP响应码302(临时性移动)。如果需要使用在300-400范围内的其他响应代码,只需在此指定即可(或使用下列符号名称之一:temp(默认), permanent, seeother)。使用它可以把规范化的URL反馈给客户端,如将”/~”重写为”/u/”,或始终对/u/user加上斜杠,等等。

注意:在使用这个标记时,必须确保该替换字段是一个有效的URL。否则,它会指向一个无效的位置!并且要记住,此标记本身只是对URL加上http://thishost[:thisport]/前缀,重写操作仍然会继续进行。通常,你还会希望停止重写操作而立即重定向,那么就还需要使用L标记。

skip|S=num(跳过后继规则)

此标记强制重写引擎跳过当前匹配规则之后的num个规则。它可以模拟if-then-else结构:最后一个规则是then从句,而被跳过的skip=N个规则是else从句。注意:它和chain|C标记是不同的!

type|T=MIME-type(强制MIME类型)

强制目标文件的MIME类型为MIME-type,可以用来基于某些特定条件强制设置内容类型。比如,下面的指令可以让.php文件在以.phps扩展名调用的情况下由mod_php按照PHP源代码的MIME类型(application/x-httpd-php-source)显示:

RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]

您可能感兴趣的文章

  • phpMyAdmin Cannot start session without errors错误解决办法
  • .htaccess如何设置防盗链某个目录的图片
  • php中$this、static、final、const、self 等几个关键字的用法
  • 利用.htaccess禁止列表目录
  • Fatal error Class 'SoapClient' not found in ...错误处理办法
  • php提示Maximum execution time of 30 seconds exceeded...错误的解决办法
  • 10 段实用的 .htaccess 代码片段
  • 利用.htaccess拒绝某ip访问网站
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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
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)

New feature in PHP version 5.4: How to use callable type hint parameters to accept callable functions or methods New feature in PHP version 5.4: How to use callable type hint parameters to accept callable functions or methods Jul 29, 2023 pm 09:19 PM

New feature of PHP5.4 version: How to use callable type hint parameters to accept callable functions or methods Introduction: PHP5.4 version introduces a very convenient new feature - you can use callable type hint parameters to accept callable functions or methods . This new feature allows functions and methods to directly specify the corresponding callable parameters without additional checks and conversions. In this article, we will introduce the use of callable type hints and provide some code examples,

What do product parameters mean? What do product parameters mean? Jul 05, 2023 am 11:13 AM

Product parameters refer to the meaning of product attributes. For example, clothing parameters include brand, material, model, size, style, fabric, applicable group, color, etc.; food parameters include brand, weight, material, health license number, applicable group, color, etc.; home appliance parameters include brand, size, color , place of origin, applicable voltage, signal, interface and power, etc.

i9-12900H parameter evaluation list i9-12900H parameter evaluation list Feb 23, 2024 am 09:25 AM

i9-12900H is a 14-core processor. The architecture and technology used are all new, and the threads are also very high. The overall work is excellent, and some parameters have been improved. It is particularly comprehensive and can bring users Excellent experience. i9-12900H parameter evaluation review: 1. i9-12900H is a 14-core processor, which adopts the q1 architecture and 24576kb process technology, and has been upgraded to 20 threads. 2. The maximum CPU frequency is 1.80! 5.00ghz, which mainly depends on the workload. 3. Compared with the price, it is very suitable. The price-performance ratio is very good, and it is very suitable for some partners who need normal use. i9-12900H parameter evaluation and performance running scores

C++ function parameter type safety check C++ function parameter type safety check Apr 19, 2024 pm 12:00 PM

C++ parameter type safety checking ensures that functions only accept values ​​of expected types through compile-time checks, run-time checks, and static assertions, preventing unexpected behavior and program crashes: Compile-time type checking: The compiler checks type compatibility. Runtime type checking: Use dynamic_cast to check type compatibility, and throw an exception if there is no match. Static assertion: Assert type conditions at compile time.

C++ program to find the value of the inverse hyperbolic sine function taking a given value as argument C++ program to find the value of the inverse hyperbolic sine function taking a given value as argument Sep 17, 2023 am 10:49 AM

Hyperbolic functions are defined using hyperbolas instead of circles and are equivalent to ordinary trigonometric functions. It returns the ratio parameter in the hyperbolic sine function from the supplied angle in radians. But do the opposite, or in other words. If we want to calculate an angle from a hyperbolic sine, we need an inverse hyperbolic trigonometric operation like the hyperbolic inverse sine operation. This course will demonstrate how to use the hyperbolic inverse sine (asinh) function in C++ to calculate angles using the hyperbolic sine value in radians. The hyperbolic arcsine operation follows the following formula -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}, Where\:In\:is\:natural logarithm\:(log_e\:k)

Advanced usage of reference parameters and pointer parameters in C++ functions Advanced usage of reference parameters and pointer parameters in C++ functions Apr 21, 2024 am 09:39 AM

Reference parameters in C++ functions (essentially variable aliases, modifying the reference modifies the original variable) and pointer parameters (storing the memory address of the original variable, modifying the variable by dereferencing the pointer) have different usages when passing and modifying variables. Reference parameters are often used to modify original variables (especially large structures) to avoid copy overhead when passed to constructors or assignment operators. Pointer parameters are used to flexibly point to memory locations, implement dynamic data structures, or pass null pointers to represent optional parameters.

What are the syntax and structure characteristics of lambda expressions? What are the syntax and structure characteristics of lambda expressions? Apr 25, 2024 pm 01:12 PM

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

Parameters of vlookup function and explanation of their meanings Parameters of vlookup function and explanation of their meanings Jan 09, 2024 pm 03:18 PM

We must have used the vlookup function when using excel. So there are several such functions, and how each function is used. As far as the editor knows, there are four vlookup functions, namely Lookup_value, Table_array, col_index_num, and Range_lookup. So let me tell you their specific usage~ The vlookup function has several parameters and the meaning of each parameter. The parameters of the vlookup function include Lookup_value, Table_array, col_index_num, and Range_lookup, a total of 4. 1.Lookup

See all articles