首页
学习
活动
专区
工具
TVP
发布

wordpress网站遇到404错误常见方法

WordPress 404页面跳转到特定页面的方法

第一种方式

打开WordPress网站模版里边的404.php,如果该404.php不存在,那么就新建一个文件叫做404.php,然后拷贝以下代码进这个页面:

header("Status: 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

header("Status: 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

(2013年1月22日更新)不好意思这里第一种方式里边的 header(“Status: 301 Moved Permanently”); 并不会实现真正的301跳转,而是返回了302跳转,现更正如下:

header("HTTP/1.1 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

header("HTTP/1.1 301 Moved Permanently");

header("Location: ".get_bloginfo('url')."#301-redirect-from-404-page");

上边代码中的#301-redirect-from-404-page,主要用来通过网站统计系统统计哪些流量是来自404页面跳转过来的。

第二种方式

拷贝以下代码到404.php页面里边,可以跳转404页面到任意你设定的页面,替换其中的xxx为你的域名和页面URL即可:

header("Status: 301 Moved Permanently");

header("Location: ");

header("Status: 301 Moved Permanently");

header("Location: ");

(2013年1月22日更新)不好意思这里第一种方式里边的 header(“Status: 301 Moved Permanently”); 并不会实现真正的301跳转,而是返回了302跳转,现更正如下:

header("HTTP/1.1 301 Moved Permanently");

header("Location: ");

header("HTTP/1.1 301 Moved Permanently");

header("Location: ");

wordpress设置“固定链接”后,页面404错误的解决方法

Apache解决方案:

/etc/httpd/conf/httpd.config 文件

原因一:Apache中的rewrite模块没有开启,去除这一行前面的#号就可以了

LoadModule rewrite_module modules/mod_rewrite.so

原因二:AllowOverride Not Enabled;服务器可能没打开AllowOverride。如果httpd.config的AllowOverride设置的是None,那.htaccess将被忽略。找到以下2处位置并修改:

Options FollowSymLinks

AllowOverride All

# … other directives…

AllowOverride All

修改完成后,要重启Apache才能生效。

service httpd restart

Nginx解决方案:

设置方式是loction / {}中添加配置:

复制代码

#加入如下一条命令即可

try_files $uri $uri/ /index.php?$args;

复制代码

修改完成后重启Nginx服务器生效。

service nginx restart

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180702A13RV300?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券