I have an .htaccess
file that looks like the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/(\d+?)/?$ index.php?cmd=$1&num=$2 [L]
RewriteRule ^(.+?)/?$ index.php?cmd=$1 [L]
</IfModule>
Basically, I'm trying to write an API that can handle requests like get_all/
or get/123/
.
The problem is, when I try to go to either of the above URLs, the cmd
parameter is always set to index.php
and the num
parameter is not set at all.
If I comment out either of the RewriteRule
lines, then requests work for the remaining, uncommented out RewriteRule, but I need to be able to handle both cases.
I am aware of the looping that occurs with mod_rewrite
, but in this case, I have no clue how to stop it. I can't even understand why the above rules are causing cmd
to be set to index.php
.
Can anyone please explain what is happening here and how to fix it?
Thank you.