问题描述
我无法将永久链接设置为以帖子名称结尾。我收到 404 错误。我得到的最接近的是将自定义永久链接设置为:
/index.PHP/%postname%
但这会导致“index.PHP”出现在 URL 中。我还更新了我的 httpd.conf 以将根目录设置为:
AllowOverride All
但是还是不行。我的 wordpress 托管在 AWS EC2 linux AMI 上。
解决方法
使用
激活 mod_rewrite 模块sudo a2enmod rewrite
并重启apache
sudo service apache2 restart
要在 .htaccess 文件中使用 mod_rewrite(这是一个非常常见的用例),请使用
编辑默认的 VirtualHostsudo nano /etc/apache2/sites-available/000-default.conf
在“DocumentRoot /var/www/html”下面添加以下几行:
<Directory “/var/www/html”>
AllowOverride All
</Directory>
再次重启服务器:
sudo service apache2 restart
编辑:
发现我的 htaccess 文件丢失了。因此,请按照此处列出的步骤进行操作:
https://wordpress.org/support/article/using-permalinks/#wheres-my-htaccess-file
- 在 wp 根目录中创建了 htaccess,在我的服务器上,它是 /var/www/html。
- 添加了上面链接中提供的必需重写规则。
- 将 htaccess 上的 chmod 设置为 775
- 将 htaccess 上的 chown 设置为 apache:apache
- 重启httpd服务
邮政名称永久链接现在可以使用了!