问题
Maybe I am missing something but I can't seem to figure this one out.
I have a ReWriteRule:
RewriteRule ^view/(\w+)$ view.php?mmdid=$1 [L]
and when I go to mydomain.org/view/3, the $_GET array is empty. There is no key 'mmdid'.
However, when I change my rule to something else, such as:
RewriteRule ^viewz/(\w+)$ view.php?mmdid=$1 [L]
it works fine when I visit mydomain.org/viewz/3. I get Array ( [mmdid] => 1 ) when printing $_GET.
There are no other rules similar to this that could conflict, and I've rebooted apache.
Any ideas on why this happens? Is 'view' a keyword or something?
Here is the contents of the Rewrite log:
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a61030/subreq] (1) [perdir /path/to/webroot/] pass through /path/to/webroot/view.php
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a54000/initial] (3) [perdir /path/to/webroot/] add path info postfix: /path/to/webroot/view.php -> /path/to/webroot/view.php/1
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a54000/initial] (3) [perdir /path/to/webroot/] strip per-dir prefix: /path/to/webroot/view.php/1 -> view.php/1
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a54000/initial] (3) [perdir /path/to/webroot/] applying pattern '^(.*)$' to uri 'view.php/1'
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a54000/initial] (4) [perdir /path/to/webroot/] RewriteCond: input='mydomain.org' pattern='^www\.mydomain\.org$' => not-matched
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2a54000/initial] (1) [perdir /path/to/webroot/] pass through /path/to/webroot/view.php
192.168.204.187 - - [15/Jun/2009:13:01:19 --0400] [mydomain.org/sid#2787ab8][rid#2930e58/subreq] (1) [perdir /path/to/webroot/] pass through /path/to/webroot/1
Here is the output of the log when using just ^v/(\w+)$....
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (3) [perdir /path/to/webroot/] add path info postfix: /path/to/webroot/v -> /path/to/webroot/v/1
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (3) [perdir /path/to/webroot/] strip per-dir prefix: /path/to/webroot/v/1 -> v/1
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (3) [perdir /path/to/webroot/] applying pattern '^v/([0-9]+)$' to uri 'v/1'
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (2) [perdir /path/to/webroot/] rewrite 'v/1' -> 'view.php?mmdid=1'
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (3) split uri=view.php?mmdid=1 -> uri=view.php, args=mmdid=1
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (3) [perdir /path/to/webroot/] add per-dir prefix: view.php -> /path/to/webroot/view.php
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (2) [perdir /path/to/webroot/] strip document_root prefix: /path/to/webroot/view.php -> /view.php
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a63038/initial] (1) [perdir /path/to/webroot/] internal redirect with /view.php [INTERNAL REDIRECT]
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (3) [perdir /path/to/webroot/] strip per-dir prefix: /path/to/webroot/view.php -> view.php
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (3) [perdir /path/to/webroot/] applying pattern '^v/([0-9]+)$' to uri 'view.php'
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (3) [perdir /path/to/webroot/] strip per-dir prefix: /path/to/webroot/view.php -> view.php
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (3) [perdir /path/to/webroot/] applying pattern '^(.*)$' to uri 'view.php'
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (4) [perdir /path/to/webroot/] RewriteCond: input='mydomain.org' pattern='^www\.mydomain\.org$' => not-matched
192.168.204.187 - - [15/Jun/2009:13:10:09 --0400] [mydomain.org/sid#2787ab8][rid#2a5ebc0/initial/redir#1] (1) [perdir /path/to/webroot/] pass through /path/to/webroot/view.php
Thank you,
回答1:
Perhaps your script name clashes with the rewrite. Try renaming your script to view.page.php, after all if you're rewriting it makes no difference what the script is called.
For more information on how your script is being called use
var_dump($_SERVER);
回答2:
'view' is not a keyword or reserved word in any way.
(Deleted debugging information that led us to the solution)
Looking carefully into the rewrite logs I see this line:
applying pattern '^(.*)$' to uri 'view.php/1'
that line shows you have MultiViews enabled (because your request is not view.php/1, but view/1), so view/ gets internally converted to view.php/ before entering the rewrite engine because there's a file with the same name and a known extension. You can either disable MultiViews for that file or dir or change the script's or directory's name so the MultiView doesn't get triggered.
回答3:
It’s probably MultiViews that’s causing this behavior. Try to disable it:
Options -MultiViews
回答4:
Vinko has it right, I think, with the RewriteCond issue. Your "view" rewrite rule has a condition that's not being met, so it's never even being tested against.
来源:https://stackoverflow.com/questions/998491/why-is-my-variable-not-being-put-into-get