让 mod_rewrite 传递 $_GET 参数? [英] Getting mod_rewrite to pass $_GET params?

查看:23
本文介绍了让 mod_rewrite 传递 $_GET 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有几个关于同一主题的其他问题,我读过,但我的略有不同.我正在尝试做一个非常基本的 mod_rewrite:

There's a couple other questions on this same topic on here that I've read, but mine is slightly different. I'm trying to do a very basic mod_rewrite:

RewriteEngine on
RewriteRule ^go/([^/\.]+)/?$ /go.php?page=$1

go.php 看起来像这样:

<?php
ini_set('display_errors',1);
if(isset($_GET['page'])){
    echo 'page='.$_GET['page'];
}else{
    echo 'oh shnizzle!';
}
?>

现在,当我在浏览器中转到 /go/someword 时,$_GET 参数someword"没有传递,我收到消息oh嘘!"每次.我无法通过 mod_rewrite 传递任何 $_GET 参数的可能原因是什么?

Now, when I go to /go/someword in my browser, the $_GET param "someword" IS NOT passed along, and I get the message "oh shnizzle!" every time. What are possible reasons I'm not able to pass any $_GET params through mod_rewrite?

推荐答案

您可能打开了 MultiViews.将此添加到 .htaccess 文件的顶部:

You probably have MultiViews turned on. Add this to the top of your .htaccess file:

Options -MultiViews

希望问题应该会消失.

为了详细说明在这种情况下会发生什么,您的 URL /go/someword 指向一个不存在的资源,因此 MultiViews 将其转换为/go.php,确实存在.发生这种情况时,/somewhere 位将作为 $_SERVER['PATH_INFO'] 传递给 PHP,但 go.php 不匹配您的重写规则,因此不会执行重写以写入该查询字符串.

To elaborate a little on what's going on if this is the case, your URL /go/someword points to a non-existent resource, so MultiViews transforms it into /go.php, which does exist. When this happens, the /somewhere bit is passed to PHP as $_SERVER['PATH_INFO'], but go.php doesn't match your rewrite rule, so the rewrite is not performed to write that query string.

这篇关于让 mod_rewrite 传递 $_GET 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆