0

Before you mark it as duplicate FIY I have tried all solutions I could find on SO.

The url is www.deltadigital.ca

config file (if I use $config['base_url'] = 'http://www.deltadigital.ca' - it doesnt work at all)

//$config['base_url']   = 'http://www.deltadigital.ca';
$root=(isset($_SERVER['HTTPS']) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

.htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|woff|eot|img|css|js|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>

It's giving me my webhost's 404 error. I tried other solutions on SO and it's either giving me 500 server error or codeidniter's 404 error

routes.php

$route['default_controller'] = "tlc/view";
$route['/([a-z]+)'] = "tlc/view/$1";
$route['404_override'] = '';

And this is my controller

class Tlc extends CI_Controller
    public function view($page='index')
    {
        if ( ! file_exists(APPPATH.'/views/tlc/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        } 
         else
         {
            $this->load->view('tlc/templates/header.php');
            $this->load->view('tlc/'.$page);   
            $this->load->view('tlc/templates/footer.php');   
        }

So basically Im trying to make menu links work. They only work with full url i.e. deltadigital.ca/index.php/tlc/view/about-us

It's CI 2.2.2, host is 1and1, my view files are in views/tlc folder

update: removed the leading slash: $route['([a-z]+)'] = "tlc/view/$1";

16
  • Surely the base URL should be blank? CI obtains that for you... Commented Jun 15, 2015 at 4:52
  • Thanks, but still doesn't work. I tried other rewrite rules after setting to blank. So is this a problem with the server settings? Commented Jun 15, 2015 at 15:35
  • Hmmm, perhaps remove the leading slash from your second route? Documentation says it is important to leave those out. Also, your base URL should be defined with the trailing slash: $config['base_url'] = "http://www.deltadigital.ca/". Commented Jun 15, 2015 at 15:52
  • Yes, I added the trailing slash ...www.deltadigital.ca/ Ive tried different rules I found online and the one Im using now is RewriteRule ^(.*)$ index.php?/$1 [L,QSA] - so it has no leading slash anyway, still doesn't work. Commented Jun 15, 2015 at 16:12
  • If I remove the leading slash its giving me 500 server error which indicates there is an error in .htaccess, with the leading slash it's just giving me my webhosts 404. Thank you anyway Commented Jun 15, 2015 at 16:16

1 Answer 1

2

Okay, as stated before I am not a CodeIgniter guru. What I do know is that the following works for me:

Config:

$config['base_url'] = "http://www.deltadigital.ca/";
# or use $config['base_url'] = "";
$config['uri_protocol'] = "REQUEST_URI";
$config['index_page'] = '';

Routes:

$route['default_controller'] = "tlc/view";
$route['(:any)'] = "tlc/view/$1";
$route['404_override'] = "";

Controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Tlc extends CI_Controller {

    public function view($page='index')
    {
        if ( ! file_exists(APPPATH.'/views/tlc/'.$page.'.php'))
        {
            // Whoops, we don't have a page for that!
            show_404();
        }
         else
         {
            $this->load->view('tlc/templates/header.php');
            $this->load->view('tlc/'.$page);
            $this->load->view('tlc/templates/footer.php');
        }
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/tlc.php */

.htaccess:

<IfModule mod_rewrite.c>

    RewriteEngine On

    # Remove /index/
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Remove trailing slashes (prevents duplicate SEO issues)
    RewriteRule ^(.+)/$ $1 [L,R=301]

    # Removes access to the system folder by users.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # If not a file or directory, route everything to CI
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    # RewriteRule ^(.*)$ index.php/$1 [L] # This is an alternative

</IfModule>

(Upon writing my answer, I see that you do not currently have the last rule, as shown.)

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

7 Comments

thank you, still the same thing, now instead of 404 its giving me 500. Im glad it works for some people. I'll keep trying
(Did you perhaps see my update? Are you 100% sure that you're using exactly what I have in my answer?)
And if you're getting a 500, what's in your Apache error logs?
I did see the update. It's a character for character copy. I did copy and paste. Thanks for your time man
I don't think I can see error logs, all I can see from 1and1 control panel is access and mail logs.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.