1

While I am working with Web API project with Slim, I was using .htaccess for API folder /v1 under root web. My OS is Ubuntu 16.04, with Apache/2.4.18. I wanted to apply the .htaccess only for the /v1 folder. The .htaccess file looks like this:

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

When I try to access file in the /v1 folder I get 404 response. For example if try to access

http://localhost/project/v1/loadSomething

The response will be 404:

Not Found
The requested URL project/v1/loadSomething was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80

I have tried to edit to make some change like this:

<Directory "/var/www/html">
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

But the response in this case is 500,

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

The logs looks like

[Sat Aug 10 21:16:11.356667 2019] [core:alert] [pid 4699] [client 127.0.0.1:33852] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Sat Aug 10 21:20:21.783996 2019] [core:alert] [pid 4700] [client 127.0.0.1:34374] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
[Sat Aug 10 21:20:40.368584 2019] [core:alert] [pid 4701] [client 127.0.0.1:34376] /var/www/html/project/v1/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Can anyone help me please?

1
  1. Since Apache 2.4 directives Order, Allow and Deny are deprecated and were replaced by the new Require syntax.

    Replace

    Order allow,deny
    Allow from all
    

    with

    Require all granted 
    

    in your config. See https://httpd.apache.org/docs/current/upgrading.html

  2. It seems mod_rewrite is not enabled in your server. Enable the module with the a2enmod command (which creates a symbolic link /etc/apache2/mods-enabled/rewrite.load pointing to ../mods-available/rewrite.load), then restart the server:

    sudo a2enmod rewrite
    sudo service apache2 restart
    

    To list all enabled modules you can use the a2query command with the -m flag:

    a2query -m
    
  • Thank you! I was not aware of the deprecation of Order, Allow and Deny. Now its working perfectly @Freddy. – Jote Aug 10 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.