Apache mod_rewrite在服务器上启用但不能正常工作吗? [英] Apache mod_rewrite is enable on server but not working?
问题描述
我最近已经安装了灯组并启用了mod_rewrite:
I have recently installed the lamp stack and have enabled mod_rewrite:
$ sudo a2enmod rewrite
$ service apache2 restart
我可以在phpinfo上看到它:
I can see it on my phpinfo:
但是当我尝试在WordPress中访问以下网址时:
But when I try to access an URL like this below in my WordPress:
http://my-localhost/my-wordpress/whats-on/
我收到此错误:
未找到
在此上找不到所请求的URL/my-wordpress/whats-on/服务器.
The requested URL /my-wordpress/whats-on/ was not found on this server.
位于127.0.0.1端口80的Apache/2.4.18(Ubuntu)服务器
Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
我还能做什么?我错过了什么吗?
What else can I do? Have I missed anything?
有什么想法吗?
我也使用.htaccess:
I have my .htaccess on too:
# 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
但是为什么?
我创建了一个简单的测试:
I created a simple test:
RewriteRule ^test.html$ test.php [L]
但是我得到404错误,而不是被定向到test.php
But i get 404 error instead of being directed to 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
我该如何解决?
推荐答案
要解决此问题,请按照以下步骤操作:
To fix this issue follow this:
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
Exit and save and restart apache with command
sudo systemctl restart apache2
结束:-)
这篇关于Apache mod_rewrite在服务器上启用但不能正常工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!