WordPress子站点resources文章跳转404问题求助
WordPress子目录站点文章404问题解决方案
针对你在AWS服务器上根目录和子目录resources各部署一套WordPress,子目录站点后台正常但文章点击跳转404的问题,按以下步骤排查修复:
1. 确认Apache mod_rewrite模块已启用
AWS服务器的Apache默认可能未开启URL重写模块,这是固定链接生效的核心:
- 登录服务器终端,执行启用命令:
sudo a2enmod rewrite # Debian/Ubuntu系统 # 若为Amazon Linux/CentOS,执行:sudo apachectl enable rewrite - 重启Apache服务使设置生效:
sudo systemctl restart apache2 # Debian/Ubuntu # Amazon Linux/CentOS执行:sudo service httpd restart
2. 修正Apache目录的AllowOverride配置
Apache默认限制了目录的.htaccess生效权限,需修改站点配置:
- 打开Apache主配置文件或站点配置文件(比如
/etc/apache2/sites-available/000-default.conf或/etc/httpd/conf/httpd.conf) - 找到对应网站根目录的
<Directory>块,将AllowOverride None修改为AllowOverride All,示例:<Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> - 重启Apache服务
3. 验证子目录WordPress的URL配置
确保子站点的URL设置与实际路径匹配:
- 登录
resources站点后台,进入设置→常规,检查:- WordPress地址(URL):
https://你的域名/resources - 站点地址(URL):
https://你的域名/resources
- WordPress地址(URL):
- 若后台无法保存,直接编辑
resources/wp-config.php,添加以下代码:define('WP_HOME','https://你的域名/resources'); define('WP_SITEURL','https://你的域名/resources');
4. 检查.htaccess文件权限
确保Web服务器有权读取.htaccess文件:
- 执行命令修正权限:
sudo chmod 644 /var/www/html/resources/.htaccess sudo chown www-data:www-data /var/www/html/resources/.htaccess # Debian/Ubuntu # Amazon Linux/CentOS执行:sudo chown apache:apache /var/www/html/resources/.htaccess
5. 排查AWS缓存/负载均衡影响
若使用了CloudFront或ELB:
- 清除CloudFront缓存,确保新的重写规则生效
- 检查CloudFront行为设置,确认允许传递查询字符串,避免缓存旧的404响应
内容的提问来源于stack exchange,提问作者Naren Verma
相关产品推荐
相关产品推荐

