Slim Framework always return 404 Error

后端 未结 8 450
独厮守ぢ
独厮守ぢ 2021-02-01 04:27

These days i\'m using Slim Framework as my simplest tool to develop the php web api. Using these two articles:

  • Coenraets
  • CodingThis
8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 04:55

    If you're using Slim on Ubuntu 16.04 and you're getting the 404 error. Try this test from Tod Birdsall above:

    If this works

    http://localhost/index.php/hello/bob

    and this doesnt work

    http://localhost/hello/bob

    and your .htaccess file in the same directory as your index.php and is configured as follows:

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

    And you still get the 404 error on Apache.

    Try turning on Apache mod_rewrite as follows and restart Apache:

    $sudo a2enmod rewrite

    $sudo service apache2 restart

    The Slim API should work correctly now as the provided .htaccess file will only work if mod_rewrite is enabled and that not the default on a clean install.

    Here is how to turn off mod_rewirte if you need to.

    $sudo a2dismod rewrite

    $sudo service apache2 restart

提交回复
热议问题