【发布时间】:2014-08-28 08:19:14
【问题描述】:
我需要在我的 wordpress 站点中捕获所有 404 并根据原始 url 请求重定向它们。例如,如果以下是 404
http://example.com/news/123.html
我需要将其重定向到
http://example.com/news
我会有多个这样的实例,比如下面的 404
http://example.com/hats/greenhat.html
会去
http://example.com/hats
我不知道如何在 Wordpress 中执行此操作。在我的 .htaccess 文件中,这是我的第一行
ErrorDocument 404 http://example.com/my-custom-404.php
但它并没有重定向到 my-custom-404.php,而是转到默认的 wordpress 404 页面。
这是我的 htaccess 供参考
ErrorDocument 404 http://example.com/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Rewrite 404s to the news section
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /news/index.php [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# THE WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
在我的文件中作为测试,我试图将所有 404 重写为 /news/index.php,但这是行不通的 - 一切仍将进入 wordpress 404 页面
【问题讨论】:
标签: wordpress .htaccess http-status-code-404