首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WordPress .htaccess和ErrorDocument 400

WordPress .htaccess和ErrorDocument 400
EN

Stack Overflow用户
提问于 2012-02-07 03:51:18
回答 2查看 801关注 0票数 0

我遇到了一个问题,固定链接.htaccess代码会阻止自定义错误处理。当我删除WordPress代码时,错误处理可以正常工作。

下面是我的代码:

代码语言:javascript
复制
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个错误的自定义错误文档?

提前谢谢你,

斯科蒂

EN

回答 2

Stack Overflow用户

发布于 2012-02-07 03:55:21

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

票数 0
EN

Stack Overflow用户

发布于 2014-05-23 02:23:44

如果您想在WordPress中使用带有当前主题的自定义错误页面,则需要执行以下操作...

在当前的

  1. 中,将.htaccess ErrorDocument条目更改为400.php模板页面。请确保包含正常的get_header()get_footer()代码。理想情况下,您的主题已经有一个functions.php

文件,所以只需复制它,重命名它,然后更改其中的内容/消息。

  • 在您的主题中添加以下代码

(您可以将此代码放在最后一行或其他任何位置)

代码语言:javascript
复制
/**
* 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' );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9166299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档