apache - Mod_rewrite in php not setting up request values -
i struggling create api points php. followed http://coreymaynard.com/blog/creating-a-restful-api-with-php/ tutorial working fine me except modrewrite part. using following in .htaccess
<ifmodule mod_rewrite.c> rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule api/v1/(.*)$ api.php?request=$1 [qsa,nc,l] </ifmodule>
with rule, if there no file or directory called api/v1
take rest of part , rewrite api.php
.
so, if have localhost/api/v1/example?apikey=w36foc4vu6
should getting $_request['request'] == 'example'
, $_get
normal.
when echo in api.php
, $_get
values not $_request['request']
(which nil). missing in configuration?
i have checked mod_rewrite in enabled. googled alot , couldn't find explanation why happening. appreciated php noob. :)
edit1: added link tutorial following.
edit2: used rewriterule api/v1/(.*)$ api.php?request=$1 [qsa,nc,l]
only in .htaccess , print_r()
, request both. $_request
array ( [apikey] => w36foc4vu6 )
for $_get
, getting
array ( [apikey] => w36foc4vu6 )
but still missing example
from key/values (the actual problem).
edit3: $_server
has
[request_uri] => /api/v1/example?apikey=w36foc4vu6 [script_name] => /api.php [path_info] => /v1/example [path_translated] => /var/www/v1/example
update: both of @mario , @eiad right. problem multiviews on. in process of turning off, found out had allowoverride none
in default config. so, .htaccess wasn't being read @ all. thank much. problem solved.
try adding
rewritebase /
and update
rewriterule ^api/v1/(.*?)$ /api.php?%{query_string}&request=$1 [l,nc,ns]
Comments
Post a Comment