Site developed in Codeigniter only loads home page - php

I'm trying to move a site developed in Codeigniter from one host to another. The only difference between hosts is that the server the site is moving from is a Windows server (with PHP etc. installed) and the new server is Linux.
However, when I uploaded the site, and changed all the url references, the site only loads the home page.
The address of the new site is http://pioneer.xssl.net/~admin341/
There is a htaccess file, which reads as follows:
<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]
#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]
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
The lines in config.php that relate to the url are:
$config['base_url'] = "http://pioneer.xssl.net/~admin341/index.php/";
$config['index_page'] = "";
Plus the developer (my predecessor) coded a url helper file:
function base_url($includeIndexPHP = true)
{
if($includeIndexPHP)
{
$CI =& get_instance();
return $CI->config->slash_item('base_url');
}
else
{
return 'http://pioneer.xssl.net/~admin341/';
}
}
Any ideas would be appreciated. Thanks.

You may well need to change the $config['uri_protocol'] around to get it working on your live site. This is often the cause of the "homepage only" routing issue in CodeIgniter.
The most common is REQUEST_URI but sometimes PATH_INFO works better.

Related

live server shows 404 error, but not on local, codeigniter 3

I have four identical pages that only differs in some identifiers but the logic is very much the same. All of them works on localhost. Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand.
I use XAMPP 3.2.2 and Sublime for developing it on local. I moved it to GoDaddy Deluxe Linux for live. My Codeigniter version is 3.1.10.
I already tried answers from most of the questions on StackOverflow:
All controller and model names' first letters are capitalized in the file name and inside the file.
All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I have two .htaccess files, one of them is inside the application folder, and one is outside. I don't know if that's confusing the system? But I have another website on a different hosting that has the same .htaccess files and they're working okay. And anyway, if that's confusing the system, why does it only affect one of the four identical pages?
.htaccess outside application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
.htaccess inside application folder:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
All of the controllers of the four files has this up top:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI
class Question1 extends CI_Controller
{
and the rest is normal code stuff that are working on three of those four files.
In config. php I have:
$config['uri_protocol'] = 'REQUEST_URI';
and base_url is great.
Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. My routes are working okay, as well.
I'm so lost right now.
PS. I have a custom 404 page. When I input assessment.com/index.php/question1 it shows that custom 404 page. But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). I think that tells something, I just don't know what.
EDIT
Here's my routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;
I opted not to do
$route['question1'] = "Question1";
in routes because it doesn't change anything.
Check your APPLICATION ENVIRONMENT mode. You can find it on your project root_folder/index.php and at line no. 57.
define('ENVIRONMENT', 'production');
Change the ENVIRONMENT mode into the development mode, that is
define('ENVIRONMENT', 'development');
Then refresh your applications again. If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. I solved it my 404 error with this code, you can check this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Answering this for the others who might come across the same problem.
Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." So definitely it's my controller that has the problem and not my routine or .htaccess files.
Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. So, unsurprisingly, from the controller's point of view, the page doesn't exist! Hence the 404.
I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place.

CodeIgniter Flexi Auth Demo is Not working

I have just installed Flexi Auth Plugin on my Linux system by exactly following the Installation Guide
When I navigate to code http://localhost/codeigniter/ It is displaying the fancy demo page. However, when I click on "Demo" Link from top menu, Its displaying page not found error
Not Found
The requested URL /auth_lite/demo was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Do I need to configure my routes.php? In the installation guide, It says only to edit the default controller like this $route['default_controller'] = "auth_lite/index";
By the way, I am very new to CodeIgniter. If any one encountered this problem, please help me.
search source-files for 'flexi_cart',
especially in three *library.php files,
there are some string-entries, that have to be
changed to your own directory.
Seems to work with that changes.
It does sound like your .htaccess file is either not working or not set as it should.
The server is looking for the filepath /auth_lite/demo where it should be passing that string to index.php.
Here's one of the most common .htaccess files for CI. Try it and see:
<IfModule mod_rewrite.c>
RewriteEngine On
# developing in a subfolder? (http://localhost/app/) change this to app/
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]
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css|js|swf|wymeditor|galleries|ffeiliau)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Try it and see.

Codeigniter form submission

So I'm rather new to Codeigniter...
I have a file on my local host that submits a form:
$id =array('id' => 'commentForm');
echo form_open("form_validate", $id);
public function form_validate()
{
$this->load->library("form_validation");
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('Cname', 'Client Name', 'required');
....
}
From what I understand is that when I hit submit on the form, it goes to the function "form_validate()"(or whatever you set at the submission page) in the controller and executes that.
The Code works just fine on my localhost, however once I upload it to my live server, instead of going to the function in the controller it looks for a page called form_validation(at least thats what I think from the URL)
I've rewritten my base path as:
$config['base_url'] = 'http://mysite.com/ci_form';
And gotten rid of the index.php under index
I've also taken the Codeigniter mod_rewrite form their site
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_form/
#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.
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#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 !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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
You're missing your controller in the form_open("form_validate"); function, that's why it's looking for a controller called form_validate.
It needs to be form_open("your_controller_name/form_validate");
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Also your forms should be in your views
Maybe this will help

CodeIgniter .htaccess links

I am new to codeIgniter and .htaccess stuff.
I already made to remove the index.php to localhost/ci/index.php/site/home.
So my home page can access now to localhost/ci or localhost/ci/site/home.
I have
Home and About
I can access Home and About if I Am on this link localhost/ci/site/home.
But once I'm on localhost/ci the problem exists because when I click to About the site is redirecting me to localhost/ci/about instead of localhost/ci/site/about. I change the links to Home and About the browser keeps adding the /site every click like
localhost/ci/site/site/site/site/site/site/home
Anyone can help me to fix the problem?
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci
#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
#Submitted by: Fabdrol
#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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
Have you looked at the URL Helper? It has many functions which will help in these situations.
First make sure you load the helper either in your Controller or autoload configuration.
anchor()
The anchor() helper would be ideal in this instance. e.g.
<?php echo anchor('home', 'Home'); ?>
base_url()
Or alternatively you could build up the href using base_url as previously mention.
About
Go to your config file and set index_page to be empty.
This will remove the index.php
and when you write links set / infront as :
Home and About
what #Svetlio said + i advise you to use site_url() when creating links
You're re-adding the main controller even though the htaccess is set to see that as the base. Writing your links as follows should fix the issue.
About
The other way around it is to run off the base at all times, which isn't really necessary but can work if you're having issues otherwise.
About
What that is going to do is echo out whatever you have set as the base URL in your config every time you write a link so if your base_url in your config is www.localhost.com the above will write www.localhost.com/about.
Don't worry you'll get the hang of it, the routing is probably the most complicated part of CI when you first start.
Home
About

CodeIgniter configuration with mod_rewrite, xampp and windows

I'm a noob to CodeIgniter and am trying to figure out the configuration for an app I'm building. Something is wrong with my setup.
I'm running XAMPP on Windows and am using an alias directory to point to the applications directory. In other words: "http://localhost/app_name/ " points to the root directory of the application. It all seems to work well until I do the .htaccess for mod_rewrite. Then every time I try to go to a controller I get pitched back to the xampp root.
My config is:
Directories
/app_root
/app_root/codeigniter // where code igniter is located.
/app_root/main // where the main app is located. It' the applications
// directory cut from code igniter and renamed.
.htaccess
<IfModule mod_rewrite.**so**>
RewriteEngine On
RewriteBase **/app_name/**
RewriteCond %{REQUEST_URI} ^codeigniter.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
index.php
$system_folder = "#codeigniter";
$application_folder = "main";
app_name/main/config/config.php
$config['base_url'] = "http://localhost/app_name/";
$config['index_page'] = "";
app_name/main/config/routes.php
$route['default_controller'] = "welcome";
I should also state that the app_name directory is an alias for a different drive than the apache root.
Apache Root: c:\xampp\htdocs\
App_name: d:\projects\app_name\development\
The alias is:
Alias /app_name "d:/projects/app name/development"
<Directory "d:/projects/app name/development">
Options Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Thanks in advance for the help... And if you don't mind please "explain" what you're doing when you answer with code. I want to know what I'm doing wrong. If you can help me with this I'll buy you a beer (via PayPal). This is frustrating.
Success!!
I finally managed to get URL rewrite working and what a long arduous journey it was. Here is what I got working finally. Take note that there is no backslash on the RewriteBase. Very interesting given what I've read. Thanks to everybody who tried to help.
# Options
Options -Multiviews
Options +FollowSymLinks
#Enable mod rewrite
RewriteEngine On
#the location of the root of your site
#if writing for subdirectories, you would enter /subdirectory
RewriteBase /app_name
#Removes access to CodeIgniter 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]
#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
#This last condition enables access to the images and css
#folders, and the robots.txt file
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
If your using XAMPP on a local machine, your should use internal rather than mod_rewrite.
It will load your pages under the alias name.
it took me a while to figure that out - apparently you should use mod_rewrite on remote servers to achieve the same thing.
RewriteBase /
in your .htaccess should be
RewriteBase /app_name/
to specify which directory it is..
First, a question. Is your $system_folder variable really set to:
$system_folder = "#codeigniter";
or was that a nerf from the weird (to me) way SO uses markdown? If it is, remove the #. It is an invalid character for directory/file names.
Next, I believe your RewriteBase should be /, since you use an alias in Apache, but don't quote me on that.
I personally use the .htaccess format supplied here: CodeIgniter URLs in the User Guide; under the heading Removing the index.php file. There are many ways to do it, however. A quick Google search yields a couple thousand.
Do you have mod_rewrite enabled? Check the forum post here.

Categories