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 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


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

[Thu Jun 14 10:30:50.138694 2018] [:error] [pid 7150] [client] PHP Stack trace:
[Thu Jun 14 10:30:50.138704 2018] [:error] [pid 7150] [client] 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
  • This depends on the application you are trying to run. Which one is it?
    – Melebius
    Jun 12, 2018 at 7:49
  • PHP web application using PHP5.6.34,mysql5.7.22,apache2.4 and mustache template Jun 12, 2018 at 8:05
  • I am sorry, your comment did not provide any information about whether (and how) your application requires the rewrite module.
    – Melebius
    Jun 12, 2018 at 8:09
  • 1
    rewrite module is Apache, not PHP. You also need to configure the thing properly to do the rewrites and restart Apache afterwards. If you still get a 404, then you need to start looking at /var/log/apache/error.log and such to determine what exactly is going on (i.e. what the server's looking for, etc.)
    – Thomas Ward
    Jun 12, 2018 at 16:52
  • 1
    Welcome to Ask Ubuntu! Could you please edit your post when you want to add information? Especially file or program output listings (with the help of the {} button in the editor toolbar) will be much more readable there; alternatively you can use a pastie service for longer listings and include the link of your pastie in your question. Overall it’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons. Thanks. Jun 14, 2018 at 8:10

2 Answers 2


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

I was required to setup Apache Virtual Hosts.

Thanks for everyone.

  • I wasn't completely sure what you meant by "Added below lines", but I figured I needed to append the lines at the bottom of the file below everything. Mar 22, 2019 at 16:25

Using Ubuntu 18.04 and Apache 2.4.39.

Fullstacks answer didn't work for me, as the default Apache-conf somehow overruled my changes. But, managed to fix this by changing /etc/apache2/apache2.conf directly (using sudo of course):

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


<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
  • I suppose that you didn't mean to remove the initial Directory tag line?
    – thoni56
    Dec 17, 2019 at 9:30
  • Good catch! Had that bit on the same line as the three backticks to start a code block, which means it won't show. Updated my answer to show the right code.
    – Maarten
    Dec 28, 2019 at 18:41

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.