php - Codeigniter URL routing issues in .htaccess -


before mark duplicate fiy have tried solutions find on so.

the url www.deltadigital.ca

config file (if use $config['base_url'] = 'http://www.deltadigital.ca' - doesnt work @ 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 webhost's 404 error. tried other solutions on , 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 controller

class tlc extends ci_controller     public function view($page='index')     {         if ( ! file_exists(apppath.'/views/tlc/'.$page.'.php'))         {             // whoops, don't have page that!             show_404();         }           else          {             $this->load->view('tlc/templates/header.php');             $this->load->view('tlc/'.$page);                $this->load->view('tlc/templates/footer.php');            } 

so im trying make menu links work. work full url i.e. deltadigital.ca/index.php/tlc/view/about-us

it's ci 2.2.2, host 1and1, view files in views/tlc folder

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

okay, stated before not codeigniter guru. know following works 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, don't have page 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 system folder users.     rewritecond %{request_uri} ^system.*     rewriterule ^(.*)$ /index.php/$1 [l]      # if not file or directory, route ci     rewritecond %{request_filename} !-f     rewritecond %{request_filename} !-d     rewriterule ^ index.php [l]     # rewriterule ^(.*)$ index.php/$1 [l] # alternative  </ifmodule> 

(upon writing answer, see not have last rule, shown.)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -