WordPress所有页面及文章跳转404 Not Found错误求助
WordPress 页面/文章404错误排查方案
问题描述
使用WordPress搭建网站,已创建3个页面和4篇文章,仅首页可正常访问,点击其余页面或文章的「查看」按钮时,出现Apache服务器的404提示:
Not Found
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at ... Port 80 // 已隐藏IP
通过自定义逻辑可获取页面或文章内容,但前端访问路径无法被服务器正确解析。
提供的配置文件
.htaccess 代码
# BEGIN WordPress # The directives (lines) between "BEGIN WordPress" and "END WordPress" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. <IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress # disable directory browsing Options All -Indexes # secure htaccess file <Files .htaccess> order allow,deny deny from all </Files> # secure spesific files <Files a_secret_file.php> order allow,deny deny from all </Files>
/etc/apache2/apache2.conf 代码
# access here, or in any related virtual host. <Directory /> Options FollowSymLinks AllowOverride All Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
排查步骤及解决方案
1. 启用Apache重写模块
WordPress的伪静态依赖mod_rewrite模块,执行以下命令启用并重启服务:
sudo a2enmod rewrite sudo systemctl restart apache2
2. 刷新WordPress固定链接设置
- 登录WordPress后台,进入「设置」→「固定链接」
- 选择非「朴素」的链接结构(如「文章名」),点击「保存更改」
- 此操作会自动更新.htaccess规则,确保URL重写逻辑生效
3. 修正.htaccess文件权限
确保文件归属和权限符合Apache运行要求:
sudo chown www-data:www-data /var/www/html/.htaccess sudo chmod 644 /var/www/html/.htaccess
4. 验证Apache配置生效
从提供的apache2.conf来看,/var/www/html目录已设置AllowOverride All,但需确认:
- 若使用虚拟主机配置,需保证该目录的
AllowOverride设置未被覆盖 - 执行
sudo systemctl restart apache2重启服务,使配置生效
5. 排查自定义代码或插件冲突
既然能通过自定义逻辑获取内容,说明WP核心数据正常,需检查:
- 当前主题的
functions.php或header.php中是否有修改URL的代码 - 暂时禁用所有插件,测试是否恢复正常,排查插件重写规则冲突
内容的提问来源于stack exchange,提问作者Naren Verma
相关产品推荐
相关产品推荐

