Ubuntu – Apache Rewrite module not working correctly

Apache2mod-rewrite

Keep on getting below error on Ubuntu 16.04 LTS.

404 Not Found
The requested URL /application/templates was not found on this server.

Apache/2.4.18 (Ubuntu) Server at 00.0.0.00 Port 80

In the error.log showing:

No such file or directory in /var/www/html/aplication/api.php on line 228

Below are my current rewrite rules:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?a=$1&b=$2&c=$3

</IfModule>

Output for tail -f var/log/apache2/error.log

[Thu Jun 14 10:30:50.138694 2018] [:error] [pid 7150] [client 172.29.9.57:38776] PHP Stack trace:
[Thu Jun 14 10:30:50.138704 2018] [:error] [pid 7150] [client 172.29.9.57:38776] PHP   1. {main}() /var/www/html/TestCopy_Report1/index.php:0

Output for find:

sudo find / -iname api.php
 find: ‘/run/user/1000/gvfs’: Permission denied
 /var/www/html/application/api.php
 /var/www/html/test1/api.php
 /var/www/html/test2/api.php
 /var/www/html/test3/api.php
 /var/www/html/test4/api.php
 /var/www/html/test5/api.php

Best Answer

Finally found a solution:

sudo nano /etc/apache2/sites-available/000-default.conf

Added below lines to `/etc/apache2/sites-available/000-default.conf

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

I was required to setup Apache Virtual Hosts.

Thanks for everyone.

Related Question