apache - Rewrite API URL with .htaccess after removing .php -
i'm making little rest api in php i'm trying rewrite url .htaccess
i'm trying rewrite url this
localhost/api/object_attributes/1/1
to
localhost/api/object/1/attributes/1
in .htaccess made condition remove .php
second 1 not working.
<ifmodule mod_rewrite.c> options +followsymlinks rewriteengine on rewriterule ^api/ api.php rewriterule ^api/object/1/attributes/1 /object_attributes/1/1 </ifmodule>
i searched on web didn't find solution , no errors / redirections.
that second rewrite rule working on not make sense in eyes. there no object found under path in http server.
i assume looking 1 of following 2 approaches. 1 not getting clear description, term "i want rewrite ... ..." ambiguous.
rewriteengine on rewriterule ^/?api/object/(\d+)/attributes/(\d+) /api.php?object=$1&attributes=$2 [end,qsa]
rewriteengine on rewriterule ^/?api/object_attributes/(\d+)/(\d+) /api.php?object=$1&attributes=$2 [end,qsa]
a general hint: should prefer place such rules inside real http servers host configuration instead of using .htaccess
style files. files notoriously error prone, hard debug , slow down server, nothing. provided situations not have control on host configuration (read: cheap hosting providers) or applications need write own rewrite rules in primitive way (which obvious security nightmare).
Comments
Post a Comment