Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Php 重写.htaccess中的规则指令含义_Php_.htaccess - Fatal编程技术网

Php 重写.htaccess中的规则指令含义

Php 重写.htaccess中的规则指令含义,php,.htaccess,Php,.htaccess,我的项目中有2.htaccess文件。这一个位于项目根目录中: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule ^(.*)$ public/$1 [L] </IfModule> 在第一行中,^$是一个正则表达式,它将URL路径与零个字符(即/页面)匹配,并重定向到公共文件夹中的实现,而无需任何额外参

我的项目中有2.htaccess文件。这一个位于项目根目录中:

 <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    public/    [L]
    RewriteRule    ^(.*)$ public/$1    [L] 
 </IfModule>

在第一行中,
^$
是一个正则表达式,它将URL路径与零个字符(即
/
页面)匹配,并重定向到
公共
文件夹中的实现,而无需任何额外参数。结尾处的
[L]
表示这是最后一条要运行的规则:如果正则表达式匹配,则不要进一步遍历
.htaccess

在第二行中,
^(.*$
是一个正则表达式,它匹配任意数量的字符,并重定向到
public
文件夹中的实现,但保留该路径。(
$1
保存第一个内部匹配的任何模式(在本例中,只有正则表达式中的一组括号)。因此,
/contact-us
,例如,将发送到
public/contact-us


在第三行中,它获取任何URL并将其在
URL
参数中传递到
index.php
文件中;也就是说,在
contact-us
示例中,
$\u GET['URL']
将是“contact-us”。

我只需添加,如果您有“第二行”,那么您就不需要“第一行”。在“第三行”中,则
PT
标志在
.htaccess
中是冗余的。
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>
RewriteRule    ^$    public/    [L]
RewriteRule    ^(.*)$ public/$1    [L] 
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]