Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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 使用Mod_rewrite和$GET变量时出现奇怪的问题_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 使用Mod_rewrite和$GET变量时出现奇怪的问题

Php 使用Mod_rewrite和$GET变量时出现奇怪的问题,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,在阅读了大量的SO问题、询问朋友等之后,我带着一个关于Apache mod_重写的奇怪问题来到这里 我正试图抓住http://api.server.com/.../results.php?id=XURL通过重写规则 很简单,您会说,我知道,我的.htaccess文件内容是: Options +FollowSymlinks RewriteEngine on RewriteRule ^results/(.*)$ results.php?id=$1 php由于调试原因非常简单,如下所示 var\u

在阅读了大量的SO问题、询问朋友等之后,我带着一个关于Apache mod_重写的奇怪问题来到这里

我正试图抓住
http://api.server.com/.../results.php?id=X
URL通过重写规则

很简单,您会说,我知道,我的
.htaccess
文件内容是:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^results/(.*)$ results.php?id=$1
php由于调试原因非常简单,如下所示

var\u dump($\u GET);
但是这个脚本总是返回
数组0{}

我应该指定我已经尝试清除标志,并由其他人更改
(.*)
类,但没有效果


谢谢你的帮助

您的重写规则与您正在使用的URL()不匹配

根据您的规则和设置,正确的URL为:

http://api.server.com/customer/2/results/123
但是,您提到已将所有内容都放在/2/文件夹中。如果2是您试图获取的ID,那么它将无法工作——URL重写仅适用于不存在的路径

相反,您应该将.htacess和results.php文件放在customer文件夹中,并使用以下URL:

http://api.server.com/customer/results/2
或将规则和URL更改为:

RewriteRule ^([0-9]+)/results$ results.php?id=$1
http://api.server.com/customer/2/results

您需要在此处禁用
多视图
选项:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteRule ^results/(.*)$ results.php?id=$1 [L,QSA,NC]

选项
MultiViews
Apache的内容协商模块使用,该模块在
mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。所以
/file
可以在URL中,但它将提供
/file.php

在重写规则中添加[QSA]标志会改变什么吗?另外,您访问脚本的URL是什么?您在浏览器中输入的URL是什么?您是在尝试捕获results.php还是重写为results.php?@T.Fabre[QSA]标志不做任何事情:/已经尝试过。@cmorrissey提供完整的URL安全吗?这是一个经典的http请求(可以通过PM发送给您)。哦,不!这里/2/是API的第二个版本。谢谢@anubhava!工作起来很有魅力。干杯