php - Apache mod_rewrite 在服务器上启用但不工作?

标签 php wordpress apache

我最近安装了灯组并启用了 mod_rewrite:

$ sudo a2enmod rewrite
$ service apache2 restart

我可以在我的 phpinfo 上看到它:

enter image description here

但是当我尝试在我的 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/

相关文章:

php - MYSQL 使用 AND 和 OR 从数据库中选择数据

php - WordPress。使用remove_cap(),即使删除此功能后仍获得 "Sorry, you are not allowed to access this page."

php - 子文件夹中设置的 Cookie 未在根目录中设置 - PHP

PHP 数组排序设置数字然后从 1

wordpress - wordpress ssl 出现 404 错误

jquery - 未捕获的类型错误 : Cannot read property 'clientWidth' of null

apache - 在没有 ServerName 的默认虚拟主机上将 HTTP 重定向到 HTTPS

node.js - Hastebin 服务器的 NPM 保持运行

regex - htaccess RewriteRule 特殊字符

php - 数据库连接错误(本地服务器到hostgator服务器)