Why?
在用 Yoast SEO 的时候发现各大搜索引擎对于 domain.name/index.php/sitemap_index.xml 的支持并不好,而且配置 sitemap 生成的时候费了很大的力气,只要去除 index.php 就会报错。再加上 index.php 实在不太美观,所以决定去除。
但是去除的时候搜索网上教程,中文的文章要么是直接修改 wordpress 设置,但是在 apache2 的情况下大概率会失败,有修改 apache2 设置的也还是停留在 httpd.conf 的远古版本。
How?
stackoverflow 这个问题下的第二个回答是我目前找到的唯一可行的方案。
大致的原理就是采用 .htaccess 来引导链接,但是需要加载 apache2 mod_rewrite 和 Indexes FollowSymLinks AllowOverride
Edit the permanent link
在 Setting -> permanent link 中选择任何一个没有 index.php 的链接,或者自定义去掉 index.php
Load mod_rewrite moudle
首先检测 apache2 中是否加载了 mod_rewrite 模块,在 info.php 中搜索 "mod_rewrite"
如果没有开启的话需要在 shell 开启:
sudo a2enmod rewrite
sudo service apache2 restart
Edit apache2 config
最后需要在 apache2 的配置文件中打开 Indexes FollowSymLinks AllowOverride,找到 Options Indexes FollowSymLinks 把 AllowOverride None 改为 AllowOverride All
sudo vi /etc/apache2/apache2.conf
------------ apache2.conf -------------
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
---------------------------------------
sudo service apache2 restart
Comments | NOTHING