0
votes

Recently I used the Apache RewriteEngine (mod-rewrite) to try rewriting this file:

api.access.php

to this directory:

/api

using this RewriteRule:

RewriteRule ^api$ api.access.php [L,QSA]

but it kept failing.

Oddly, replacing /api with some other string like /apis worked. So what was the problem?

2

2 Answers

4
votes

Actually that is not really a bug. Apache is pretty well tested for a long time. What you're probably running into is content Negotiation and MultiViews. It might be causing some funny business.

So your answer really won't help anyone because changing the file name is not a solution. You probably just needed to disable MultiViews.

Options -MultiViews
RewriteEngine on
RewriteRule ^api/?$ api.access.php [L,QSA]

More on MultiViews

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

0
votes

The problem turned out to be the name of the file I was trying to replace (api.access.php), because it started with api.

Changing the filename to access.api.php fixed it.

Hope this is of use to anyone out there.

Cheers