RestApi server code not working

I am trying to write server code RestAPi

and I am very stuck.

My directory structure /var/www/html/RestApi/rest/

. I am writing sever code in this folder. My .htaccess file is located at /var/www/html/.htaccess and the files below. Installing mine. htaccess

file

/var/www/html/<br>
          |<br>
          |<br>
          |--- index.php, .htaccess<br>
          |<br>
          |---/RestApt/rest/api.php (restapi server code)<br>
              /RestApt/rest/ .... (Other files to support api.php)<br>

      

.htaccess

looks like

  RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^/RestApt/rest/(.*)$ /RestApt/rest/api.php?request=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/RestApt/rest/(.*)$ /RestApt/rest/api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^/RestApt/rest/(.*)$ /RestApt/rest/api.php [QSA,NC,L]

      

Now in my api.php I have one api:

private function users(){
    // Cross validation if the request method is GET else it will return "Not Acceptable" status
    if($this->get_request_method() != "GET"){
        $this->response('',406);
        }
        ...
    }

      

After all this, when I call RestApi from browser using chrome RestAPi extension, I get the following error

The requested URL was /RestApi/rest/users

not found on this server.

In my apache file, /etc/apache2/apache2.conf

I have already done the following modification

AllowOverride All

      

I'm really stuck, please throw in some light.

+3


source to share


1 answer


Try removing the very first line /

from the rewrite rules. They should look like this:

RewriteRule ^RestApt/rest/(.*)$

      



Also I noticed a possible typo: RestAp t

+1


source







All Articles