Search code examples
php.htaccessubuntuapache2

.htaccess produces 404 on server, but passes htaccess validators


I'm stumped as to why this isn't working. When I use an online .htaccess validator all appears fine. It works as expected. However, that same .htaccess on the production server nets a 404 response.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api/index.php?_REQUEST=$1 [NC,L]

In 000-default.conf

<Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
</Directory>

For some context. The site uses a subdomain. It's running on an AWS EC2 instance with Ubuntu 20.04.2 LTS, Apache2 2.4.41, and PHP 7.4.3

This exact same configuration works just fine on another instance, the only difference being the subdomain. The desired result:

subdomain.example/api/data/data rewrites to subdomain.example/api/index.php?Querystring

Sending data/data as a querystring. While I am no .htaccess expert, far from it, I am stumped as to why this isn't working and producing a 404.


Solution

  • The resolution: Make sure you haven't left the same .htaccess file in the actual directory you are trying to rewrite. In this case, api/. Removing the errant .htaccess file and rebooting apache resolved the issue.