我最近安装了灯组并启用了 mod_rewrite:
$ sudo a2enmod rewrite
$ service apache2 restart
我可以在我的 phpinfo 上看到它:
但是当我尝试在我的 WordPress 中访问如下 URL 时:
http://my-localhost/my-wordpress/whats-on/
我收到此错误:
Not Found
The requested URL /my-wordpress/whats-on/ was not found on this server.
Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
我还能做什么?我错过了什么吗?
有什么想法吗?
我也打开了 .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my-wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my-wordpress/index.php [L]
</IfModule>
# END WordPress
但是为什么呢?
编辑:
我创建了一个简单的测试:
RewriteRule ^test.html$ test.php [L]
但是我收到 404 错误,而不是被定向到 test.php
Not Found
The requested URL /mod_rewrite/basic/test.html was not found on this server.
Apache/2.4.18 (Ubuntu) Server at 127.0.1.1 Port 80
我该如何解决这个问题?
最佳答案
要解决此问题,请按照以下步骤操作:
sudo nano /etc/apache2/apache2.conf
查找:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
替换为:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
退出并保存并使用命令重新启动apache
sudo systemctl restart apache2
结束:-)
关于php - Apache mod_rewrite 在服务器上启用但不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41921034/