Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 looks like this:

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

Options -MultiViews

And the problem should go away, hopefully.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...