PHP无法从重写规则中查看查询字符串
我的PHP无法从重写规则中查看查询字符串,php,.htaccess,mod-rewrite,query-string,Php,.htaccess,Mod Rewrite,Query String,我的.htaccess看起来像 RewriteEngine On RewriteRule ^api/([^/]*)$ /api.php?method=$1 [L,QSA] class API { public function __construct() { require_once('helpers.php'); } public function test() { dd('hey'); } }; $ap
.htaccess
看起来像
RewriteEngine On
RewriteRule ^api/([^/]*)$ /api.php?method=$1 [L,QSA]
class API {
public function __construct()
{
require_once('helpers.php');
}
public function test()
{
dd('hey');
}
};
$api = new API;
$method = isset( $_GET['method'] ) ? $_GET['method'] : null;
dd($_REQUEST, $_GET);
if( $method && method_exists($api, $method) ){
$api->{$method}();
}
else {
exit("Nothing to see here governor.");
}
我的api.php
看起来像
RewriteEngine On
RewriteRule ^api/([^/]*)$ /api.php?method=$1 [L,QSA]
class API {
public function __construct()
{
require_once('helpers.php');
}
public function test()
{
dd('hey');
}
};
$api = new API;
$method = isset( $_GET['method'] ) ? $_GET['method'] : null;
dd($_REQUEST, $_GET);
if( $method && method_exists($api, $method) ){
$api->{$method}();
}
else {
exit("Nothing to see here governor.");
}
然而,当我访问重写的url时,例如site.com/api/test
我看到了
array (size=0)
empty
如果我将其更改为/api.php?method=test
或/api/test?method=test
,我会得到
array (size=1)
'method' => string 'test' (length=4)
为什么无法检测到查询字符串
服务器设置为Apache2.2,php fmt 5.6
谢谢因为从
api
开始的URI是同一个PHP处理程序api.PHP
我怀疑这是多视图的问题
在.htaccess的开头使用此行将其关闭:
Options -MultiViews
MultiViews
选项由Apache的内容协商
模块使用,该模块在mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。所以/api
可以在URL中,但它将提供/api.php
来确认,这确实解决了我的问题!