2017-02-21 9 views
0

У меня такая же проблема, как и у CodeIgniter: 404 Page Not Found on Live Server. В приложении/контроллерах, у меня есть Welcome.php так:404 при доступе к Codeigniter page

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Welcome extends CI_Controller { 

    /** 
    * Index Page for this controller. 
    * 
    * Maps to the following URL 
*  http://example.com/index.php/welcome 
* - or - 
*  http://example.com/index.php/welcome/index 
* - or - 
* Since this controller is set as the default controller in 
* config/routes.php, it's displayed at http://example.com/ 
* 
* So any other public methods not prefixed with an underscore will 
* map to /index.php/welcome/<method_name> 
* @see https://codeigniter.com/user_guide/general/urls.html 
*/ 
public function index() 
{ 
    $this->load->view('welcome_message'); 
} 

Однако, когда я иду в mysite.com, mysite.com/welcome, mysite.com/Welcome и mysite.com/Welcome.php, Я получаю 404 каждый раз.

Мой routes.php:

$route['default_controller'] = "home"; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 

У меня есть файл, home.php:

<?php 

if (!defined('BASEPATH')) exit('No direct script access allowed'); 

class Home extends CI_Controller { 

    public function __construct() { 
    parent::__construct(); 
    $this->load->model('general_model'); 
    } 

    public function index() { 
    $this->load->view("home/home_view"); 
    } 

    /* 
    public function coming(){ 
    $this->load->view("home/coming_soon_view"); 
    } 
    */ 
} 

Мой .htaccess:

RewriteEngine on 
    RewriteCond $1 !^(phpMyAdmin|index\.php|robots\.txt) 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

<IfModule authz_core_module> 
    Require all denied 
</IfModule> 
<IfModule !authz_core_module> 
    Deny from all 
</IfModule> 

Я действительно изо всех сил, чтобы увидеть что я делаю неправильно.

+0

Что вы 'config [' index '] 'var установлено? – Kisaragi

+0

Изнутри config.php? –

+0

yes, '$ config ['index_page']' – Kisaragi

ответ

1

У меня есть этот опыт на общем хостинге, а затем как-то найти в Интернете, но забыл, кто дает этот пример, может быть, вы можете попробовать.

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading 
    # slashes. 
    # If your page resides at 
    # http://www.example.com/mypage/test1 
    # then use 
    # RewriteBase /mypage/test1/ 
    RewriteBase/
    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

Когда вы установите ваш base_url в

$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://'; 
$config['base_url'] = $protocol . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']); 

Тогда это все, что вам необходимо в файле .htaccess

RewriteEngine on 
# → Internally route to /index.php 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

Вы можете расширить его позже, просто использовать минимальную настройку прямо сейчас.

+0

Я пробовал это и работает, когда у меня есть $ route ['default_controller'] = "welcome"; но не $ route ['default_controller'] = "home"; –

+0

Теперь я настроил его, но всякий раз, когда я перехожу на tripmatcher.herokuapp.com/login, он отображает только 404, несмотря на то, что в моих контроллерах есть login.php. –

+0

работает, когда вы добавляете index.php в URL? – qwertzman

0
<IfModule mod_rewrite.c> 
     RewriteEngine on 
     RewriteBase/
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^(.*)$ /index.php/$1 [L] 
</IfModule> 

Это то, что сработало для меня.