Search code examples
codeigniterurlbase-urlrewriting

Code igniter base_url bugging, or url_rewriting?


Thanks in advance for all the help you will give me guys. I am kind of desperate now, I do not know what to do. I guess the problem comes from my base_url, but it can also come from my .htaccess that has url_rewriting on ? I have a code igniter project that works on localhost.

Whenever I click on a link, it adds a "localhost:8888" :

I have a page with following url : http://localhost:8888/my_project/ And when I click on a link on this page, it points me to : http://localhost:8888/localhost:8888/my_project/procedure/student

I do not get why it adds that localhost:8888 in between ? (if I manually take off the localhost:8888 in the url, the page works and loads correctly)

Here is my constants file defining my base_url :

define("URL", (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] );
define("SITE_URL", 'http://localhost:8888/my_project/');

Here is my .htaccess :

Options +FollowSymlinks -Indexes
RewriteEngine On
#RewriteBase /

## in case the URL is not an actual FILE
RewriteCond %{REQUEST_FILENAME} !-f

## or an actual directory
RewriteCond %{REQUEST_FILENAME} !-d

## send everything to the index, for MVC
#RewriteRule ^.*$ ./index.php

RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

DirectoryIndex index.php index.html

Here is also my config.php base_url line :

$config['base_url'] = 'http:/localhost:8888/my_project/';

The links are generated in the view as follows : id);?> so that should give for example localhost:8888/my_project/teacher/7 but when I hover the link there is localhost:8888/localhost:8888/my_project/teacher/7

Am I doing anything wrong ?

Thanks in advance for your help!


Solution

  • After series of debugging (through comments), conclusion becomes that bug was in wrongly written base url in config file. It should be changed from:

    $config['base_url'] = 'http:/localhost:8888/my_project/';
    

    to

    $config['base_url'] = 'http://localhost:8888/my_project/';// notice double slash at beginning
    

    Consequently, Medal of Honor was proposed to me and I am still thinking should I take it for pointing this silly mistake that every of us experienced once or should I wait for some biggest error ever somewhere on site and then take that deserved acknowledgment. :)