wordpress網站遇到404錯誤常見方法

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


分享到:


相關文章: