Reputation: 258
I have the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/(.*)$ api.php?m=$1 [QSA,NC,L]
</IfModule>
The URL rewriting works great. I can go to http://myserver.com/api/example and it will behave as if I went to http://myserver.com/api.php?m=example. The problem is that the PHP $_REQUEST and $_GET variables are empty. Shouldn't I still be able to get the value of $_REQUEST['m']?
After some googling, I found a suggestion to disable MultiViews. If I add Options -MultiViews
, I get a 404 error.
What am I doing wrong? Thank you.
Upvotes: 2
Views: 852
Reputation: 143886
Sounds like you don't have mod_rewrite enabled. Since it's not enabled, the IfModule
container is ignored. See: How to enable mod_rewrite for Apache 2.2
You must turn off Multiviews
in order for this to work, otherwise mod_negotiation is activated and will automatically map /api/
to /api.php
without giving mod_rewrite a chance to do anything. So you need the line:
Options -MultiViews
If you can't enable mod_rewrite, you could alternatively change your api.php script so that it looks in the PATH_INFO variable:
$_SERVER['PATH_INFO']
to get the "example" part.
Upvotes: 2