Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mod rewrite 将重写规则与[L]标志匹配后,重写不会停止_Mod Rewrite_Url Rewriting - Fatal编程技术网

Mod rewrite 将重写规则与[L]标志匹配后,重写不会停止

Mod rewrite 将重写规则与[L]标志匹配后,重写不会停止,mod-rewrite,url-rewriting,Mod Rewrite,Url Rewriting,我想将路径/health重写为/health.php 我目前拥有以下.htaccess文件,其中包含一个“一网打尽”规则: 所以我在“一网打尽”之前添加了一条新规则: RewriteEngine On RewriteRule ^health$ health.php [L] RewriteRule ^.*$ index.php [L] 但令我惊讶的是,当我在浏览器中请求/health时,它没有重写为health.php 但是,当我删除最后一条(全部捕获)规则时,它会按预期工作 为什么mod_re

我想将路径
/health
重写为
/health.php

我目前拥有以下
.htaccess
文件,其中包含一个“一网打尽”规则:

所以我在“一网打尽”之前添加了一条新规则:

RewriteEngine On
RewriteRule ^health$ health.php [L]
RewriteRule ^.*$ index.php [L]
但令我惊讶的是,当我在浏览器中请求
/health
时,它没有重写为
health.php

但是,当我删除最后一条(全部捕获)规则时,它会按预期工作


为什么mod_rewrite在将规则与
[L]
标志匹配后不停止处理规则?

找到了它。我一直认为,
[L]
标志停止了所有规则的处理,句号。实际上,它只是停止处理当前规则集中的规则,然后对重写的请求重新运行整个规则集

因此,我的catch-all代码最终捕获了它,如图所示:

在上找到的解决方案涉及将条件放在“全部捕获”规则之前,以仅在之前未处理内部重定向时执行该规则:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^.*$ index.php [L]
strip per-dir prefix: [...]/public/health -> health
applying pattern '^health$' to uri 'health'
rewrite 'health' -> 'health.php'
add per-dir prefix: health.php -> [...]/public/health.php
strip document_root prefix: [...]/public/health.php -> /health.php
internal redirect with /health.php [INTERNAL REDIRECT]

strip per-dir prefix: [...]/public/health.php -> health.php
applying pattern '^health$' to uri 'health.php'
strip per-dir prefix: [...]/public/health.php -> health.php
applying pattern '^.*$' to uri 'health.php'
rewrite 'health.php' -> 'index.php'
add per-dir prefix: index.php -> [...]/public/index.php
strip document_root prefix: [...]/public/index.php -> /index.php
internal redirect with /index.php [INTERNAL REDIRECT]

strip per-dir prefix: [...]/public/index.php -> index.php
applying pattern '^health$' to uri 'index.php'
strip per-dir prefix: [...]/public/index.php -> index.php
applying pattern '^.*$' to uri 'index.php'
rewrite 'index.php' -> 'index.php'
add per-dir prefix: index.php -> [...]/public/index.php
initial URL equal rewritten URL: [...]/public/index.php [IGNORING REWRITE]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^.*$ index.php [L]