0

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
  • This depends on the application you are trying to run. Which one is it? – Melebius Jun 12 '18 at 7:49
  • PHP web application using PHP5.6.34,mysql5.7.22,apache2.4 and mustache template – Anand H Jun 12 '18 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 '18 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 '18 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. – David Foerster Jun 14 '18 at 8:10
1

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.

  • 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. – Jasper Citi Mar 22 at 16:25
0

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>

To

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

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.