skip to Main Content

New to CodeIgniter and getting my feet wet.

Older (5yr old?) CI website. Moved it to new webhosting at A2 and got things set up.

Home page appears, however, the base URL doesn’t seem to be working for the site. I have not made DNS changes yet, so using IP and sub-folder on the FTP.

application/config/config.php

$config['base_url'] = 'http://xxx.xxx.xx.xxx/blah.com/';

also tried

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/blah.com/';

but when site loads, css is missing as it’s trying to load

<link href="/assets/css/global.css" rel="stylesheet" type="text/css" media="all" />
<link href="/assets/css/public.css" rel="stylesheet" type="text/css" media="all" />

etc.

even though the URL in the browser shows

http://xxx.xxx.xx.xxx/blah.com/

the assets and stuff are trying to be loaded at

http://xxx.xxx.xx.xxx/

Here is my htaccess file.

# Deny access to the htaccess file
<FILES .htaccess>
order allow,deny 
deny from all
</FILES>

# Prevent these script from executing anything
Options -ExecCGI
AddHandler cgi-script .pl .py .jsp .shtml .sh .asp .cgi

# Make it so sessions are available on all sub-domains
#php_value session.cookie_domain .prelicensetraining.com

# Prevent directory browsing
Options -Indexes

# Code Igniter Clean URL Rewrites
RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ index.php?/$1 [L]  

Extra notes: Was initially have trouble with a 500 internal server error on new webhosting at A2. Opened ticket and received the following from support. Now it’s connecting to db, but as I mentioned above, the base URL setting is not working properly.

“This was due to the software using an older mysql extension, which is no longer supported under PHP 7+. We installed cPanel’s MultiPHP system and set blah.com to use PHP 5.6, then updated the application/config/database.php file to use ‘localhost’ as the database host and we now get a login page at http://xxx.xxx.xx.xx/blah.com/ .”

2

Answers


  1. Please try this

    <link href="<?php echo base_url();?>assets/css/global.css" rel="stylesheet" type="text/css" media="all" />
    

    Also check it in the inspect element OR right click on your site and click on View page Source to see the correct path of the file and change accordingly.

    Login or Signup to reply.
  2. You are not using the base_url in your HTML code, you are currently “manually” loading the assets:

    <link href="/assets/css/global.css" rel="stylesheet" type="text/css" media="all" />
    

    The / at the start tells the browser to load the assets from the root folder.

    You can use the base_url() function to generate links, this function is available if you load the URL helper, you can use it like this:

    base_url('assets/css/global.css');
    

    This will return:

    http://xxx.xxx.xx.xxx/blah.com/assets/css/global.css

    So use it like this:

    <link href="<?=base_url('assets/css/global.css');?>" rel="stylesheet" type="text/css" media="all" />
    

    <?= is the same as <?php echo

    You can load the URL helper with this code:

    $this->load->helper('url');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search