Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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
为什么$\u GET=index.php_Php_Regex_.htaccess_Mod Rewrite - Fatal编程技术网

为什么$\u GET=index.php

为什么$\u GET=index.php,php,regex,.htaccess,mod-rewrite,Php,Regex,.htaccess,Mod Rewrite,在.htaccess文件中,我有: RewriteEngine On RewriteBase / RewriteRule ^([^/]+)/?$ index.php?ToDo=$1 [L,QSA] 在执行打印时($\u GET),它会输出 Array ( [ToDo] => index.php ) 但是,当我将重写规则更改为 ^([^/.]+)/?$ index.php?ToDo=$1 [L,QSA] print\u r然后输出$\u GET是一个空数组。有人能解释一下为什么会发

在.htaccess文件中,我有:

RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?ToDo=$1 [L,QSA]
在执行打印时($\u GET),它会输出

Array ( [ToDo] => index.php ) 
但是,当我将重写规则更改为

^([^/.]+)/?$ index.php?ToDo=$1 [L,QSA] 

print\u r然后输出$\u GET是一个空数组。有人能解释一下为什么会发生这种情况吗

让我们以URI
/abc
为例:

您的第一个正则表达式:

^([^/]+)/?$
匹配
/abc
并将其重写为:

/index.php?ToDo=abc
/index.php?ToDo=index.php
现在,
mod_rewrite
引擎再次运行,并再次匹配URI
/index.php的regex
^([^/]+)/?$
,并将其重写为:

/index.php?ToDo=abc
/index.php?ToDo=index.php
你的第二个正则表达式:

^([^/.]+)/?$
工作正常,因为它与
/index.php
URI不匹配

编写此规则的最佳方法如下:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?ToDo=$1 [L,QSA]

如果请求是针对有效文件或目录的,这两行将阻止重写。

什么URL生成此输出?完整URL位于我的本地服务器上,并输出//local.test/Fantastic;谢谢你,阿努巴瓦!当选项可用时,我将接受此选项。我很欣赏这个解决方案。解释得很好,+1:)