今天在更改wordpress固定链接后,点击文章便会出现找不到文章的404界面,在网上搜索一番后,发现是apache没有开启rewrite模块。

cd /etc/apache2/mods-enabled目录,ls -ltr 发现rewrite.load是日期最新的文件,证明rewrite是生效了,但是验证还是报404,然后网上搜索一番,并没有找到像网上说的那样

  • 方法1. 进入/etc/apache2/sites-enabled,修改000-default文件。在其中搜索AllowOverride,找到,将None改为All,保存退出。重启apache。
  • 方法2. 进入apache的httpd.conf,在其中搜索AllowOverride,找到,将None改为All,保存退出。重启apache。

仔细确认之后,发现自己的apache2文件夹中根本没有以上方法中说的文件,最终确定在apache2.conf中找到了AllowOverride,此时按照网上方法将None更改为All(全部更改)

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride All
        Require all granted
</Directory>

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

此时打印出phpinfo,发现apache已经开启了rewrite模块,更改了固定链接之后也能正确跳转到文章。