【问题标题】:wordpress site work on local but not works on online serverwordpress 网站在本地工作,但不能在在线服务器上工作
【发布时间】:2013-09-20 09:18:04
【问题描述】:

我的 wordpress 站点在本地服务器上正常工作,但是当我在服务器 404 页面上上传它时,显示未找到错误。

我检查了我的 index.php 是否正确重定向。 这是代码:-

      <?php

       define('WP_USE_THEMES', true);

       /** Loads the WordPress Environment and Template */
         require('./wp-blog-header.php');
             ?>

我检查了我的 wp-blog-header.php,它也可以工作。因为我将它转发到 phpinfo 页面和显示的信息页面,但没有显示网站页面。 这是 wp-blog-header 代码:-

             if ( !isset($wp_did_header) ) {

       $wp_did_header = flase;

  require_once( dirname(__FILE__) . '/wp-load.php' );

wp();

//wp_redirect( ABSPATH . WPINC . '/template-

          loader.php' , 301 );
                    // exit;
                require_once( ABSPATH . WPINC . '/template-loader.php' );
          }
          ?>

而我的 temp-loader.php 是:-

       <?php
      /**
     * Loads the correct template based on the visitor's url
        * @package WordPress
       */
    if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
do_action('template_redirect');

     // Halt template load for HEAD requests. Performance bump. See #14348
       if( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) )
exit();

       // Process feeds and trackbacks even if not using themes.
       if ( is_robots() ) :
do_action('do_robots');
return;
    elseif ( is_feed() ) :
do_feed();
return;
       elseif ( is_trackback() ) :
include( ABSPATH . 'wp-trackback.php' );
return;
         endif;

    if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) :
$template = false;
if     ( is_404()            && $template = get_404_template()            ) :
elseif ( is_search()         && $template = get_search_template()         ) :
elseif ( is_tax()            && $template = get_taxonomy_template()       ) :
elseif ( is_front_page()     && $template = get_front_page_template()     ) :
elseif ( is_home()           && $template = get_home_template()           ) :
elseif ( is_attachment()     && $template = get_attachment_template()     ) :
    remove_filter('the_content', 'prepend_attachment');
elseif ( is_single()         && $template = get_single_template()         ) :
elseif ( is_page()           && $template = get_page_template()           ) :
elseif ( is_category()       && $template = get_category_template()       ) :
elseif ( is_tag()            && $template = get_tag_template()            ) :
elseif ( is_author()         && $template = get_author_template()         ) :
elseif ( is_date()           && $template = get_date_template()           ) :
elseif ( is_archive()        && $template = get_archive_template()        ) :
elseif ( is_comments_popup() && $template = get_comments_popup_template() ) :
elseif ( is_paged()          && $template = get_paged_template()          ) :
else :
    $template = get_index_template();
endif;
if ( $template = apply_filters( 'template_include', $template ) )
    include( $template );
return;
       endif;
         ?>

我的 htaccess 文件是:-

    Options +FollowSymlinks
      RewriteEngine on
         # BEGIN WordPress
       <IfModule mod_rewrite.c>
          RewriteEngine On
         RewriteBase /
         RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        </IfModule>
        # END WordPress


    # PROTECT WP-CONFIG 
        <Files wp-config.php> 
           order Allow,Deny 
          Deny from all
           </Files>

请告诉我如何在线运行我的网站。

【问题讨论】:

  • 当我从 templat-loader.php 中删除“if ($template = apply_filters('template_include', $template))”此代码时,我的代码运行但未格式化,如果我写这个条件代码不起作用

标签: php .htaccess wordpress wordpress-theming


【解决方案1】:

在使用 WordPress 时,这确实是一个令人沮丧的问题。但我会尝试分享一些我的经验。

0) Enable debugging mode:在 wp-config.com 中将 WP_DEBUG 更改为 TRUE 并添加以下行:

error_reporting(E_ALL);
ini_set('display_errors', true);

有了这个,我们会让 WP 显示比我们想要的更多的错误;)

提示:在本地机器上使用它来制作防弹插件/主题/项目

1) 检查 404 是来自默认浏览器还是来自 wordpress:尝试访问 wp-admin url。这是检查域是否设置正确的好方法。有时错误是找不到 index.php,所以我们需要加载一些不关心插件和主题的东西,这就是我建议使用 wp-admin 的原因。

提示:即使是无主题安装,wp-admin 也会正常工作

2) 删除任何可能出现问题的内容:如果我们在前面的步骤中找不到确切的问题,我们需要弄脏:重命名 THEMESPLUGINS 文件夹,以确保问题不在于任何插件。

提示:有时插件文件开头的空行可能会完全破坏您的项目

3) 提供链接:我还不能发表评论,但如果你给我一个链接来查看错误,我会很高兴帮助你。

【讨论】:

  • 嗨,感谢您的帮助,抱歉,我是 word press 的新手。根据您的建议,我在浏览器上看到错误消息。但不知道我如何纠正这个问题,请你再帮我一次,这里是错误消息:----------------------------注意:wp_enqueue_script被错误地调用。在 wp_enqueue_scripts、admin_enqueue_scripts 或 init 挂钩之前,不应注册或排队脚本和样式。有关更多信息,请参阅 WordPress 中的调试。此消息在 function.php 中
  • 我忘了告诉你的另一件事是我的 wp-admin 也在工作,但网站不工作
  • 很好,我停用了 woocommerse 结帐管理器插件,所有 eroors 都消失了,但它再次显示“无法显示请求的页面”错误。现在发生了什么?
  • 错误 403 表示权限被拒绝 (en.wikipedia.org/wiki/List_of_HTTP_status_codes) 所以这意味着:文件权限错误。
  • problem found.problem 在我的主题中。很抱歉给您带来麻烦。
【解决方案2】:

在将 wordpress 站点从本地服务器迁移到 Live 服务器时。 我们需要考虑以下步骤:

  1. wp-config.php 中的数据库配置
  2. 站点 url:如果您正在开发 woocommerce 站点,那么我们可以手动更改整个数据库中的站点 url。所以有更好的解决方案搜索和替换脚本。 以避免 404 问题。
  3. 将此脚本放在根文件夹中,并将旧网址替换为新网址。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2021-10-01
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    相关资源
    最近更新 更多