2012-02-06 38 views
0

我遇到了永久.htaccess代码阻止自定义错误处理的问题。当我删除WordPress代码时,错误处理工作正常。WordPress .htaccess和ErrorDocument 400

这里是我的代码:

php_value memory_limit 96M 
php_value upload_max_filesize 250M 
php_value post_max_size 250M 

# BEGIN 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> 

# END WordPress 

ErrorDocument 400 /error.php 

AddType application/msword doc 
AddType application/vnd.ms-excel xls 
AddType application/powerpoint ppt 
AddType application/vnd.ms-word.document.macroEnabled.12 .docm 
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx 
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx 
AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm 
AddType application/vnd.openxmlformats-officedocument.presentationml.template potx 
AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam 
AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm 
AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx 
AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm 
AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx 
AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam 
AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb 
AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm 
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx 
AddType application/vnd.ms-excel.template.macroEnabled.12 xltm 
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx 

有没有办法让WordPress的代码不变,仍然有400错误自定义错误文档?

由于提前,

斯科蒂

回答

0

WordPress的作品使用引导index.php文件。 wordpress目录中的所有请求都由它处理。因此,自定义错误文档不能通过apache工作,您需要在您使用的Wordpress主题中为它们创建模板页面。

+0

感谢您的答复。我添加了链接到我创建的页面,如下所示: ErrorDocument 400/page-name/ 这仍然会产生相同的结果。有没有不同的语法我缺少? – Scotty 2012-02-06 21:14:17

+1

这应该解释我在说什么。 http://codex.wordpress.org/Creating_an_Error_404_Page – thenetimp 2012-02-07 04:34:30

0

如果你想使用自定义错误页与WordPress的您当前的主题,你需要做到以下几点...

  1. 你的.htaccess的ErrorDocument项更改为ErrorDocument 400 /index.php?error=400
  2. 创建400.php您当前的WordPress主题中的模板页面。一定要包括正常的get_header()get_footer()的代码。理想情况下,您的主题已有404.php文件,因此只需复制此文件,重命名它,然后更改其中的内容/消息。
  3. 下面的代码添加到您的functions.php

(你可以把这个最后一行或其它地方)

/** 
* 400 Error Code Reponse Header 
* Note: This allows you to specify 400 RewriteRules in the .htaccess to use a custom 400.php WordPress template. 
* Source: http://otroblogmas.com/retornar-410-wordpress/ 
* 
* @param string $template 
* @return string 
*/ 
function e12_response_400($template) { 
    if('400' == $_SERVER['REDIRECT_STATUS']) { 
     status_header(400); 
     if(file_exists(STYLESHEETPATH . '/400.php')) { 
      return STYLESHEETPATH . '/400.php'; 
     } 
    } 
    return $template; 
} 
add_filter('template_include', 'e12_response_400');