PHP Slim Framework: The requested URL was not found on this server

CodeMonkey

For one of the projects, i am using Slim Framework http://www.slimframework.com/ to create restful APIs in PHP.

I did a manual install for the framework by copying it in the PHP project folder using instructions at https://github.com/slimphp/Slim.

Later i updated my .htaccess as well.

For my project, I have the following Directory Structure

project\
----slim\
----tests\
----index.php
----.htaccess

For this, the Get call i.e. http://someIp/project/ works for me. It fetches the standard "Welcome to Slim! Congratulations! Your Slim application is running. If this is your first time using Slim, start with this "Hello World" Tutorial." However, post/patch/delete and other get are not working. Not even get for hello. It gives the not found error.

http://someIp/project/hello/:name The requested URL /project/hello/:name was not found on this server.

http://someIp/project/post The requested URL /project/post was not found on this server.

Updated my .htaccess file as :

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Still it is failing.

When i made changes into the apache config file to allowOverride = all, it failed even for the GET call on index.php. For sure, it is not mapping from .htaccess.

I am still clueless what changes i need to make to .htaccess or any other file to get it working.

Here is the code:

\Slim\Slim::registerAutoloader();

/**
 * Step 2: Instantiate a Slim application
 *
 * This example instantiates a Slim application using
 * its default settings. However, you will usually configure
 * your Slim application now by passing an associative array
 * of setting names and values into the application constructor.
 */
$app = new \Slim\Slim();

/**
 * Step 3: Define the Slim application routes
 *
 * Here we define several Slim application routes that respond
 * to appropriate HTTP request methods. In this example, the second
 * argument for `Slim::get`, `Slim::post`, `Slim::put`, `Slim::patch`, and `Slim::delete`
 * is an anonymous function.
 */

// GET route
$app->get(
    '/',
    function () {
        $template = "hi";
        echo $template;
    }
);

//$app->get(
//    '/v1/status/',
//    function() {
//        echo "status";
//    }
//);
//
$app->get('/hello/:name', function ($name) {
    echo "Hello, $name";
});

// POST route
$app->post(
    '/post',
    function () {
        echo 'This is a POST route';
    }
);

// PUT route
$app->put(
    '/put',
    function () {
        echo 'This is a PUT route';
    }
);

// PATCH route
$app->patch('/patch', function () {
    echo 'This is a PATCH route';
});

// DELETE route
$app->delete(
    '/delete',
    function () {
        echo 'This is a DELETE route';
    }
);

/**
 * Step 4: Run the Slim application
 *
 * This method should be called last. This executes the Slim application
 * and returns the HTTP response to the HTTP client.
 */
$app->run();
CodeMonkey

The following steps worked for me :

Changes in apache2.conf

1. Get the path of running Apache
    ps -ef | grep apache
   Append -V argument to the path
    /usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE

2. Naviagte to apache2.conf
    vi /etc/apache2/apache2.conf

3. Update the file Replace "AllowOverride None" to "AllowOverride All"
    <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>
4. Restart apache2 after
    service apache2 restart
   OR
    apachectl -k graceful

Changes in .htaccess

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Changes in .htaccess inside subdirectory

RewriteEngine On
RewriteBase /project
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Enable mod_rewrite for Apache 2.2

1. Type the following command in the terminal
    a2enmod rewrite
2. Restart apache2 after
    service apache2 restart

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

.php requested URL not found on server

PHP - The requested URL was not found on this server

The requested URL was not found on this server. on php codeigniter

the requested URL / was not found on this server

Not Found The requested URL was not found on this server

Codeigniter PHP Object not found, The requested URL was not found on this server

"The requested URL was not found on this server" error in laravel php project

PHP Request - The requested URL /.$final_link was not found on this server

Codeigniter The requested URL was not found on this server

laravel the requested url was not found on this server

the requested URL was not found on this server django

Requested url not found on server error

The requested URL not found in this server in Wordpress?

CPanel The requested URL / was not found on this server

CodeIgniter, Requested URL not found on server

The requested resource / was not found on this server PHP

404 Not Found The requested URL /xxxxx was not found on this server

Google Play : the requested URL was not found on this server

"The requested URL / was not found on this server." Heroku/Django

The requested URL was not found on this server,installing phpmyadmin

Google Speech API: the requested URL was not found on this server

The requested URL / was not found on this server., django openshift

Django requested URL was not found on this server in TestClass

cs-cart The requested URL was not found on this server

AJAX: "The requested URL was not found on this server" on localhost

flask-restful : The requested URL was not found on the server

Angular - The requested URL /home was not found on this server

centos wordpress the requested URL was not found on this server,

Requested URL not found on the server in XAMPP using laravel

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive