views:

195

answers:

5

Hey everyone,

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  A: 

'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.

Vinko Vrsalovic
I have posted the output of the log @ level 9, cleared other rules and requested the page once.
barfoon
Yes, I have 2 rules below to remove www:RewriteCond %{HTTP_HOST} ^www\.mydomain\.org$RewriteRule ^(.*)$ http://mydomain.org/$1 [R=301,L]
barfoon
+2  A: 

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);
rojoca
This did it! Thank you. Didnt even think of that.Why cant you name the script the same thing as the rule?Can anyone shed some light on this?
barfoon
To some it might make a difference as it keeps things more organized in the webroot.
barfoon
Renaming the file is rather removing the symptoms than removing the cause. And that’s not a good solution.
Gumbo
@Gumbo - I agree, I dont think I understood why you cant name them the same thing. I posted an answer, if anyone has any further insight they can leave a comment there. Thanks!
barfoon
@Gumbo - I would agree as well. @Vinko has some insight into the effect of MultiViews (and is perhaps more deserving of the answer credit). If this is indeed the problem, then renaming the script is a valid solution.
rojoca
+1  A: 

It’s probably MultiViews that’s causing this behavior. Try to disable it:

Options -MultiViews
Gumbo
A: 

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.

dirtside
A: 

Why cant you name the script the same thing as the rule? I.e view.php and view/x? Can anyone shed some light on this?

Is this solely because of MultiViews?

barfoon
See my answer... I think the problem is the combination of MultiViews and mod_rewrite where the URL path has the same name as the executable.
Vinko Vrsalovic