在 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
在error.log中显示:
No such file or directory in /var/www/html/aplication/api.php on line 228
以下是我当前的重写规则:
<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>
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
查找的输出:
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
答案1
最终找到了解决办法:
sudo nano /etc/apache2/sites-available/000-default.conf
将以下几行添加到“/etc/apache2/sites-available/000-default.conf”
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
我需要设置 Apache 虚拟主机。
谢谢大家。
答案2
使用 Ubuntu 18.04 和 Apache 2.4.39。
Fullstacks 的答案对我不起作用,因为默认的 Apache-conf 以某种方式否决了我的更改。但是,通过直接更改 /etc/apache2/apache2.conf(当然使用 sudo),设法解决了这个问题:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
到
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>