Codeigniter duplicates base_url ()

I am having a problem with Codeigniter that duplicates base_url. If I visit the index page in the controller, all the URLs are fine, but when I visit the page which is not the index page in the controller (cooling in my case), I get strange duplicate URLs like thishttp://www.mypage.si/www.mypage.si/services/colling

for example

This is my service manager

class Services extends CI_Controller {

    public function index() {
        $this->load->view('header');
        $this->load->view('main');
        $this->load->view('footer');
    }

    public function cooling()   {
        $this->load->view('header');
        $this->load->view('cooling');
        $this->load->view('footer');
    }
}

my .htaccess file

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

config.php

$config['base_url'] = 'www.mypage.si/';
$config['index_page'] = '';

This is my HTML.

     <li><a href="<?php echo base_url('services/cooling'); ?>">cooling</a></li>
     <!-- results in: http://www.mypage.si/www.mypage.si/services/cooling-->
     <img src="assets/images/logo.png" />
     <!-- results in: http://www.mypage.si/www.mypage.si/assets/images/logo.png -->
     <li><a href="<?php echo base_url()."services/cooling"; ?>">cooling</a></li>
     <!-- results in: http://www.mypage.si/www.mypage.si/services/cooling-->

Thank you in advance!

+4
source share
2 answers

Codeigniter by default will not add the current protocol to your base url, to fix your problem simply update:

$config['base_url'] = 'www.mypage.si/';

to

$config['base_url'] = 'http://www.mypage.si/';

, , , url, .

$config['base_url'] = "http".((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) ? "s" : "")."://".$_SERVER['HTTP_HOST']."/";

:

IIS, , HTTPS $_SERVER global .

+6

$config['base_url'] = 'www.mypage.si/';

$config['base_url'] = 'http://www.mypage.si/';

site_url base_url . :

<li><a href="<?php echo site_url('services/cooling'); ?>">cooling</a></li>
+2

Source: https://habr.com/ru/post/1616261/


All Articles