0

I recently uploaded my codeigniter project onto my web server.

it's in a folder called project1 this is what my directory view looks like

[www.myurl.com]
  |-> project1
        |-> application
        |-> css
        |-> images
        |-> js

I am having two problems.

The first is that I want it to load my welcome view when I go to (www.myurl.com) and not (www.myurl.com/project1/main_controller/index.php/welcome). How do i get rid of all that garbage?

The second problem is when I use <?php echo base_url();?> it shows up fine in view source but when I click on it, it echo's the url [www.myurl.com/project1/www.myurl.com/project1/] why is it doing this?

tereško
  • 58,060
  • 25
  • 98
  • 150
Undermine2k
  • 1,481
  • 4
  • 28
  • 52

2 Answers2

2

It looks like you've installed CodeIgniter into a subdirectory. If you want your CI site to load from the root url, you should copy it one directory up so the Application & System folders are directly under the root url of your web directory. From there, the .htaccess rules that are posted by shail (and quoted below) should take care of removing the index.php in your paths.

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

Regarding the site_url() issue, make sure you have your $config['base_url'] variable set in application/config/config.php and that it contains the trailing slash.

$config['base_url'] = "http://www.myurl.com/";

To test this further, try passing a parameter to the site_url() function like this:

echo site_url(welcome);

Which should return: http://www.myurl.com/welcome if everything is set right.

nageeb
  • 2,002
  • 1
  • 13
  • 25
1

Getting CI up and running is rather simple. Most of it requires you to edit a few configuration files.

You need to setup CI to point to the right base URL of the app. To do this, open up system/application/config/config.php and edit the base_url array item to point to your server and CI folder. view plaincopy to clipboardprint?

$config['base_url'] = "http://localhost/ci/";  

Currently, the CI setup will have a default controller called “welcome.php”; you can find this in the system/application/controllers folder. For this tutorial, delete it and open your system/application/config/routes.php file. Change the default array item to point to the “helloworld” controller. view plaincopy to clipboardprint?

$route['default_controller'] = "Helloworld" 

CI also has a view file that we do not need. Open up the system/application/view/ folder and delete the welcome_message.php file.

You can change your default controller here.

In order to edit Url http://localhost/ci/index.php/helloworld/.There are a few things you can do to improve your CodeIgniter experience - like removing that annoying index.php bit out of the URL. You can accomplish this task by creating a .htaccess file in the root folder, and adding the following code.

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

You’ll also need to open up the config.php file in system/application/config/ and edit the index_page array item to a blank string. view plaincopy to clipboardprint?

$config['index_page'] = "";   

Another nifty trick is to turn on CI’s ability to parse PHP alternative syntax if its not enabled by the server. To do this, open up the same file as before, system/application/config/config.php, and set the rewrite_short_tags array item to TRUE. view plaincopy to clipboardprint?

$config['rewrite_short_tags'] = TRUE;  

I hope all goes well!

chhameed
  • 4,406
  • 4
  • 26
  • 44
Shail
  • 1,565
  • 11
  • 24