0
if(){
redirect('Login');
}

I have a condition above that redirect the page to log in depending on some values. I can see in url that I get redirect because when I enter

http://www.myapp.com it changes to http://www.myapp.com/Login

Now In my route I have:

$route['default_controller'] = 'welcome';
$route['Login'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

My Login controller looks like:

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

class Login extends CI_Controller {

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

    public function index(){
        $data['title'] = 'GYM';
        $this->load->view('login',$data);
    }

}

In my view I have

image

But why Im getting

Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404
www.myapp.com
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.7

I cant figure out where I got configuration wrong

Update: change config file:

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';//'AUTO';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

and

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

accessing:

http://www.myapp.com/index.php/Login

Works but all the above does not. I not getting why

guradio
  • 15,524
  • 4
  • 36
  • 57

2 Answers2

1

Try including below lines on the .htaccess at the root level of the codeigniter app folder :

RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA] 
Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26
  • I finally figure out can you include in your answer. TH .htaccess that should be edited is the one which is in level with the application not the one level with the view. I need to ad that one. Please add it as answer as you are the first one to answer it. I will accept it as the correct answer – guradio Aug 02 '18 at 04:45
  • happy coding mate – guradio Aug 02 '18 at 05:01
0

change your value like following

$route['login'] = 'Login';

$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';

if not work, replace this code in htaccess

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Anfath Hifans
  • 1,588
  • 1
  • 11
  • 20
  • when I access `http://www.myapp.com/index.php/Login` it works but all the above does not. I not getting why. I tried your solution not working either – guradio Aug 02 '18 at 04:35