Problems uploading codeigniter project from localhost to live server - codeigniter

I have developed a project in codeigniter. Now i want to move it from localhost to a live server. But i moved it, the website opens the first time and when i refresh the page, then it just shows the blank page. I tried in another browser, there was also the same problem. After 30 minutes when i tried to open the website, it opens the first time and then again on refreshing the site, the blank page appears.
Upon closing the browser and opening it again, the page opens first time and then after refreshing it does not work neither it goes to other pages.
I do not understand where is the problem. Please someone should help me.

Try this .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>

Folowing are the contents of my config.php file.
$config['base_url'] = 'http://mysyite/folder/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd'; // experimental not currently in use
$config['log_threshold'] = 4;
$config['log_path'] = '';
$config['cache_path'] = '';
$config['rewrite_short_tags'] = FALSE;

This is the index.php file.
switch (dirname(__FILE__)){
case 'C:\wamp\www\ems\public_html' :
$env = 'development';
break;
default :
$env = 'production';
break;
}
define('ENVIRONMENT', $env);
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
$system_path = '../system';
$application_folder = '../application';
Please someone should help, I am in a very trouble and I have very less time for this project. #CodeGodie

Related

URL Segment in Codeigniter

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

main page of Codeigniter not found

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.

Routes not working codeigniter

Routes not working and default controller showing error 404 when I am setting welcome as a default controller then all routes defined with the welcome controller working but my other routes and url not working.
$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';
All above routes are working with only welcome controller.
$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';
Showing error 404 for all controllers and functions.
If you put index.php after domain this will work.
http://www.example.com/index.php/login/
You should remove index.php from url by replacing in config and .htaccess
replace in config.php
$config['index_page'] = 'index.php';
by
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
This is what worked for me:
In config.php of config folder, use: $config['enable_query_strings'] = FALSE;
Use $config['uri_protocol'] = 'AUTO';
Use $config['index_page'] = '';
Also remember to set your base url. Mine is: $config['base_url'] = 'http://localhost/code';
Finally use the following htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /code/index.php/$1 [L]
</IfModule>
NB: Remember to edit your path to index.php in the htaccess file. Hope this works for you

404 not found only index.php is working

I have finished a project and it works fine with my local server however when I put it on a live server, it gives me 404 Not Found - 404.html when I tried to access other pages. Only index.php is working the rest is not. I am using codeigniter 2.2.0. To check if there's a problem with my code I uploaded default codeigniter. I have only two pages welcome.php and one.php. Here's the live url, http://www.fhi365.com/
here is my config file.
$config['base_url'] = 'http://www.fhi365.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Here is my constant
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/');
here is my route
$route['default_controller'] = "welcome";
$route['404_override'] = '';
Here is my controller
public function index()
{
$this->load->view('welcome_message');
}
public function one(){
$this->load->view('one_view');
}
I did not touch .htacces.
Can somebody help me.
Thanks.
You should trust codeigniter base_url() OR site_url() . They always return the right url.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
You must pay attention to .htaccess. If is enable
if ROOT
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
If SUBFOLDER
RewriteEngine on
RewriteBase /directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
This is how the problem was solved.
#Florin said to trust codeigniter.
So this is my config
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
#Shaiful Islam said that I need to put "?" to index.php on my constant.
This is my constants
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?/');
Wew! This works fine for me.

CodeIgniter redirect loop in subfolder on server

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.

Resources