i have a codeigniter website
even the default controller is Welcome
http://www.immodernafrican.com/index.php/Welcome
but this website is not opening on http://www.immodernafrican.com can anyone help me regarding this issue
Thanks
Regards
Please insure your controller file name first character Uppercase Welcome.php
and can insure your $route['default_controller'] = "Welcome";
Class names must start with an uppercase letter.
This is valid:
<?php
class Welcome extends CI_Controller {
}
This is not valid:
<?php
class welcome extends CI_Controller {
}
Also .htaccess copy and paste :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Also insure $config['uri_protocol'] = 'AUTO'; in application/config/config.php file
Related
In my codeigniter project, i am working around the url parameter. Its almost working but there is some problem in the view page which is loading.
I have set all the configuration as per my knowledge. But I doubt there must be some issue in the .htaccess or routes.php file.
.htaccess file --
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
routes.php --
$route['default_controller'] = 'home';
$route['home'] = 'home/index';
$route['faq'] = 'home/faq';
$route['privacy-policy'] = 'home/policy';
$route['doupnow-videos'] = 'home/videos';
$route['doupnow-audios'] = 'home/audios';
$route['morevideo/(:any)'] = 'home/morevideo/$1';
$route['moreaudio'] = 'home/moreaudio';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Controller Page --
public function morevideo($cat)
{
$result['list']=$this->Home_Model->displayVideosAll($cat);
$this->load->view('header');
$this->load->view('doupnow-video-more', $result);
$this->load->view('footer');
}
Now when i navigate to "http://doupnow.com/morevideo/latest", this page getting the parameter correctly and also displaying the data based on the parameter only but the view is not getting the html and css elements like the other pages.
Kindly give me the proper direction. Thank You.
On your site, when you're linking to a script or stylesheet, you link it by doing:
/js/script.js
But you need to give the full url like this:
http://doupnow.com/js/script.js
I have a problem with my CI project in my linux server (there is no problem in windows wamp),
in my project every route works fine except main page (address http://example.com without any query string), that shows 404 error.
here my configs :
htaccess :
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Options -Indexes
php_flag output_buffering On
my routes.php :
$route['default_controller'] = 'index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['index'] = 'index/index';
$route['/'] = 'index/index'; // i have controller index.php and action index for first page that load with address example.com/index/index
my config.php:
$config['base_url'] = 'http://example.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //and "REQUEST_URI" both tested.
any help would be appriciated.
This problem of "it works on Windows but not on Linux" is almost always due to incorrect file naming. It appears your 'default_controller' class is named "index". Both the file name and the class declaration MUST use an uppercase first character.
In other words, the file must be Index.php (note the uppercase I) and the declaration must be
class Index extends CI_Controller
Again, note the uppercase "I" in Index.
All that said, CodeIgniter documentation clearly states that a controller should NOT be named Index. So, pick some other name.
I'm trying to setup codeigniter for our website.
if I want the main page to be http://example.com
and my folder structure looks like this:
public_html\
application\
common\
system\
how do I setup codeigniter to show the page when going to http://example.com? I'm getting a 404 error when viewing it.
I edited config.php, but im not sure what to put for my base url.
my htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
my routes.php
$route['default_controller'] = "HomeController";
$route['404_override'] = '';
my HomeController.php
public function index()
{
$this->load->model('HomeModel');
$this->load->view('templates/header');
$data['result'] = $this->HomeModel->function1();
$this->load->view('index', $data);
$this->load->view('templates/footer');
}
my HomeModel.php
<?php
class HomeModel extends CI_Model{
public function index()
{
}
public function function1()
{
$query = $this->db->get('work_orders');
//return $query->result();
return $query->result_array();
}
}
EDIT2:
Edit your default_controller from HomeController to homecontroller Like this:
$route['default_controller'] = "homecontroller";
and rename (if needed) your controller from HomeController.php to homecontroller.php and in your Controller itself call it Homecontroller.
Do the same for the model. call it homemodel.php (or home_model.php) in your directory and Call it Homemodel in your model itself.
Also clear your browser cache.
EDIT1:
Rename your model. I guess you called your model HomeModel.php. just call it home_model.php. this should fix your problem.
Your .htaccess file should look like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
This is just copied from my server and it works great.
After then, change your default_controller to:
$route['default_controller'] = "the default controller";
and if public_html is a folder you created your index page should be:
$config['index_page'] = "public_html/";
otherwise leave it blank. (if it's your server's httpdocs)
should work :)
At your router.php in config folder there is an line
$route['default_controller'] = "your controller name";
add your controller that you want to display defaultly
You can make base_url empty:
$config['base_url'] = '';
Try this working .htaccess conf:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
IF nothing helps then hosting doesn't support mod_rewrite apache module
I am new to Codeigniter and using Codeigniter 1.7, I created a .htaccess file in root directory with code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
to remove index.php from urls, and added
$config['url_suffix'] = ".html";
to config.php file to provide default suffix for all pages. After that I created a controller test.php with this code:
class Test extends Controller{
function test(){
parent::Controller();
}
function index(){
$this->load->view('test');
}
}
and a view also:
<?php
echo anchor(current_url(), 'This Page');
?>
When I navigate to http://localhost/ci/test.html it works fine, but when I click the link auto generated by anchor() function in my view it goes to http://localhost/ci/index.php/test.html
How can I remove /index.php/ from urls generated by anchor() function?
Also when i point to home page
localhost/ci/index.html
it shows me a 404 Page not found error but when I point to
localhost/ci/index.php
it works fine. Why home page is not being converted to index.html instead of index.php?
You have to create a rewrite condition with htaccess.
To remove index.php, add this to the root folder .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*) /index.php/$1 [L]
If your loading Test as your default controller then this will be your base url
localhost/ci/
or
localhost/ci/test/
or
localhost/ci/test/index.html
Make sure to set your config.php to this
$config['index_page'] = ''
You should also be using Codeigniter 2.1 for proper php 5 support.
Also your constructor funciton should be like so if using php 5. Else stick with what you have for php 4.
public function __construct()
{
parent::__construct();
}
I'm stuck with redirect loop when I deploy the files from localhost to my server.
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
The site is multilingual and I'm using .htaccess file to remove the index.php from the uri. I'm trying to deploy the site to a subfolder in my domain (i.e http://www.mydomain.com/subfolder) and ideally I want the urls like this (http://www.mydomain.com/subfolder/en/welcome)
My .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
I have also tried:
RewriteEngine on
RewriteBase /subfolder/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
My config.php:
$config['base_url'] = 'http://www.mydomain.com/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
My routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['^../products/(:num)'] = "products/products_list/index/$1";
$route['^../products'] = "products/products_list/index";
$route['^../products/detail/(:num)'] = "products/product/index/$1";
$route['^../(.+)$'] = "$2";
And finally MY_Config class for i18n:
class MY_Config extends CI_Config {
function site_url($uri = '')
{
if (is_array($uri))
{
$uri = implode('/', $uri);
}
if (function_exists('get_instance'))
{
$CI =& get_instance();
$uri = $CI->lang->localized($uri);
}
return parent::site_url($uri);
}
}
This setup works fine in my local environment, I access via http://local.subfolder.com, I set a virtual host to do this, but this setup doesn't work when I deploy to the server in a subfolder.
I would be really glad if someone can point where the problem is. Sorry for the long post, but wanted to give as much as information.
Thanks in advance
I'd try removing the trailing slash from RewriteBase
RewriteBase /subfolder
And also modifying your RewriteCond
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I've noticed that using the ? before /$1 seems to work sometimes in CI too.
Very useful doc:
http://codeigniter.com/wiki/mod_rewrite/
if u want to use the htaccess for a particular folder., u just put your htaccess with in that folder. for ex.,
if ur using five virtual hosting like v1,v2,v3,v4,v5. And if u want to use your htaccess in v3, just put that file within that folder.