0

I called base_url() in the form action in a view in my local machine. But, it is giving the url as http://::1/codeigniter/ instead of http://localhost/codeigniter. This is the same case with the site_url() also.

Is it a problem with the .htaccess file or should I make any settings in config.php?

Below is my .htaccess file:

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

I am using CodeIgniter 3.0 version.

8
  • whats there in config.php file? Commented Dec 8, 2015 at 13:21
  • What is the value of $config['base_url'] in config? Commented Dec 8, 2015 at 13:21
  • I didn't make any changes in config.php. I am asking if I should any setting in that file. Commented Dec 8, 2015 at 13:22
  • @deepakb : Its null. $config['base_url'] = ''; Commented Dec 8, 2015 at 13:23
  • 1
    $config['base_url'] = 'http://localhost/codeigniter'. Set this in your config and check if it working! Commented Dec 8, 2015 at 13:24

2 Answers 2

1

If you leave it blank the framework will try to autodetect it since version 2.0.0. Try to set that value in config: $config['base_url'] = 'http://localhost/codeigniter/' and I think everything should works.

Edit: with trailing slash.

Sign up to request clarification or add additional context in comments.

1 Comment

With version 3.0.x auto detection should not be relied on. It should always be configured in config.php codeigniter.com/user_guide/installation/…
1

If you don't want to change $config['base_url'] , while changing the server or moving the project to a live server from local machine , try this :

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = "$root";

This can possibly avoid all issues with $config['base_url'] .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.