首页 文章

在Wordpress中调用CodeIgniter get_instance会导致404

提问于
浏览
0

在过去的一天里,我一直在努力使用Codeigniter很好地使用Wordpress . 我有一个用Codeigniter编写的父应用程序,我试图用来控制对Wordpress安装的访问 .

到目前为止,我已经获得了一个Codeigniter实例(通过get_instance())以显示并进行必要的修改以使两个应用程序在大多数情况下保持彼此的方式 .

但是,现在关于Wordpress网站的根index.php之后的任何事情我都会遇到问题 .

URL的外观类似于/ parent / content / external / wordpress,其中“parent”是Codeigniter根文件夹,wordpress是Wordpress根文件夹 .

我可以加载example.com/parent/content/external/wordpress(有或没有index.php)但是像wordpress / sample-page这样的东西会导致Codeigniter 404错误 .

似乎Codeigniter正在尝试将URL解析为控制器和方法,但是失败了 . 我在CI日志中收到404错误,指向Wordpress网址的第一部分(上例中的示例页面) .

有没有人知道如何通过推送到Wordpress index.php文件中的代码加载CI以停止尝试解决?

粘贴在下面的文件的内容 . 谢谢!

<?php

// BEGIN: CodeIgniter setup

// Remove the query string
$_SERVER['QUERY_STRING'] = '';  

// Include the codeigniter framework
define("REQUEST", "external");
require('/home/magicmag/magicmagazine.com/x/index.php');

// Create CI instance
$CI =& get_instance();

// Authenticate user with custom redirect
$CI->user = $CI->xlib->isLoggedIn(FALSE);

// Custom redirect
if(!$CI->user) {
    redirect('/user/login?d=/content/ext/magic-live-2015');
}

#ToDo: Rewrite this so that the destination is determined by current URL or by the starting URL of the external content

// Check for existing auth
if(!isset($CI->user['ext-magic-live-2015'])) {
    // User isn't currently authenitcated to the external content

    // Try to authentical
    $CI->user['ext-magic-live-2015'] = $CI->xlib->hasExtAccess($CI->user['userId'], '1'); // MAGIC Live is extId 1

    // If authenticated
    if($CI->user['ext-magic-live-2015']) {

        // Store it in the session
        $CI->session->set_userdata('ext-magic-live-2015', $CI->user['ext-magic-live-2015']); #ToDo fix hardcoded name
    } else {
        // Not authenticated
        $CI->session->set_flashdata('danger', 'You do not have access to that content.');
        redirect('/');
    }
}


// END: CodeIgniter setup

// UNEDITED WORDPRESS INDEX.PHP IS BELOW

/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */

define('WP_USE_THEMES', true);

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

这是Codeigniter .htaccess文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /x/

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

1 回答

  • 0

    确定您的.htaccess不允许访问word press目录并将触发任何URI_REQUEST到codeigniter index.php,以便允许访问wp目录添加一个新的条件规则,如此

    #allow access to wp directory 
    RewriteCond %{REQUEST_URI} ^parent/content/external/wordpress.*
    RewriteRule ^(.*)$ /$1 [L]
    

    所以你的.htaccess会是这样的

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /x/
    
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #When your application folder isn't in the system folder
        #This snippet prevents user access to the application folder
        #Submitted by: Fabdrol
        #Rename 'application' to your applications folder name.
        RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]
    
        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
    
        #allow access to wp directory 
        RewriteCond %{REQUEST_URI} ^parent/content/external/wordpress.*
        RewriteRule ^(.*)$ /$1 [L]
    
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin
    
        ErrorDocument 404 /index.php
    </IfModule>
    

    你可以在这里测试.htaccess http://htaccess.madewithlove.be/

    当你要求举例时, parent/content/external/wordpress/11/22/33

    你将被重定向到wp而不会被ci index.php“ grab ”

    如果它仍然不起作用只是玩线

    RewriteCond %{REQUEST_URI} ^parent/content/external/wordpress.*

    一点点

    希望有所帮助

相关问题