Reputation:
So I have the following rewrite in an htaccess file:
RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
Whenever I try to go to http://domain/index
I get a 404, but when I try to go to http://domain/index.
or even a non-existent page like http://domain/a
, the rewrite works just fine and index.php var_dump()
s the appropriate values.
The only code in index.php is var_dump($_GET);
, so I know it's not a php issue.
Can someone explain to me what's wrong with my rewrite rule, and explain how to fix it?
EDIT: I forgot I had error logging enabled. The error it keeps saving to error.log is:
[Sun Feb 24 21:01:18 2013] [error] [client 192.168.1.1] Negotiation: discovered file(s) matching request: /path/public_html/index (None could be negotiated).
Upvotes: 1
Views: 1532
Reputation: 221
When MultiViews
is enabled (Options +MultiViews
), the Content Negotiation
module looks for files that match index
, but .php
files don't qualify for a match, so it fails with None could be negotiated
. You can add .php
handlers as matches using:
MultiviewsMatch Handlers Filters
as documented in MultiviewsMatch
.
Upvotes: 1
Reputation: 11799
By the error, it seems MultiViews is enabled.
You may try this at the top of the file:
Options +FollowSymlinks -MultiViews
Additionally, I suggest the following:
# Prevent loops
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L]
MultiViews provides for Content Negotiation
, best described here
Upvotes: 3