CodeIgniter not working with subfolders - codeigniter

I have my codeigniter code in web root. The mod_rewrite is enabled.. I checked through phpinfo.php. Now the code structure is something like this
controllers/home.php(default controller)
controllers/products.php (not listed in routes.php under config)
and then a subfolder
controllers/members/login.php
The urls I am trying are
domain_name/ ---------> works
(Note: this is where my echo base_url is pointing me to I guess
because $config['index.php'] = '', But even setting it to index.php is
not pointing me to the working index.php url)
domain_name/products ------> doesn't work
domain_name/index.php/products ------> works
similarly
domain_name/members ----->doesn't work
domain_name/index.php/members --->work
Because this thing is working with index.php I am guessing the routes.php is working fine. But some how echo $base_url is pointing me to these without index.php urls.
I have tried the .htacess file which is in my webroot that is /var/www/
The version for codeigniter is 2.1.3
Please help. I want this to work with or without index.php and if you can explain what i am missing please give me explaination.

In General Codeigniter tends to explicity hide index.php when call the its main root but when your trying to access its subfolders directly in the url .. index.php is required.In order to do that so you must include an .htaccess inside your ci filesystem that will accept the use of domain/product or domain/index.php/product
So try to include this .htacess and change its rewrite base into your ci folder name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cifolder
#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
</IfModule>

Related

CodeIgniter Site is not working after changing domain and move on another hosting

I have a CodeIgniter site on production and the URL is http://example.com/ear, it means site is running as folder structure.
Now I am moving the site from production to another staging environment and also changing the domain to http://ear.example.com. I have change the base URL in config file and also the database details under database.php but the site is showing 500 error. The error is "ear.abc.com is currently unable to handle this request."
Can someone help me? I am copying my .htaccess file here. Please feel free to write me for any query.
<IfModule mod_rewrite.c>
RewriteEngine On
#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 !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
NOTE: I can't share the exact domain name due to client policy so I am taking "example" in place of actual domain name.

Codeignitier mod_rewrite and parent folder

I am using CodeIgniter and I am trying to remove the index.php from the urls. I have mod_rewrite enabled in Apache, I set the index to a blank string in the CI config file and I am using the .htaccess file found at the bottom of the page. I think part of the problem might be that my application and system folders are not in my document root. My local server folder structure looks like this:
mysite.dev/
-public_html (server root)
-application
-system
-.htaccess
I did it that way because I read that it would be extra security having the application and system outside of the public_html folder. But the rewrite rules aren't working and I suspect it has something to do with this. I'm relatively new to this so I really appreciate any help!
my htaccess file:
<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
#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
</IfModule>
I have used that code in my .htaccess file as it's working for me.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

CodeIgniter and mod_rewrite with multiple applications

I'm trying to use CodeIgniter for multiple applications along with mod_rewrite for the application folder/name.
My CodeIgniter structure is as follows:
webroot/appone/
webroot/apptwo/
webroot/system/
webroot/index.php
webroot/appone.php
webroot/apptwo.php
I followed the example listed here to use CI with multiple apps. http://codeigniter.com/wiki/Multiple_Applications/
I'm looking to use mod_rewrite that will show the following:
domain.com/appone/
domain.com/apptwo/
I believe Dirk is correct.
Here's the code I'm using (got it from Elliot Haughin) on every app folder and it works fine. Just change APP_FOLDER_NAME to whatever you wish appone, apptwo etc.
have an .htaccess file on each folder with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /APP_FOLDER_NAME
#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
</IfModule>
PS. Don't forget to remove the index.php and define base url on CI config.
Cheers.

Codeigniter routing to an href id

I've made a one-page design and would like to route somesite.com/contact to somesite.com/index.php#contact. I'm using a href id's and div id's. But none of the routes i make seems to be working.
examples:
$route['contact'] = "pagescontroller/index#contact";
$route['contact'] = "base_url('#contact')";
How could i make this work?
Thanks in advance!
You will need to use the # so the browser knows you are going to a part of the page. If you really want to remove it, you could use it as a parameter for the controllermethod you use to display your page and use javascript to go the that specific id on your page.
I would not do that since you will reload your page every time you click on a link. (Unless you use javascript to suppress that as well and go to the relevant ID.)
You could however use mod_rewrite in .htaccess for removing the index.php from your url. So your url's will look like http://example.com/#about
My .htaccess-file for codeigniter is this:
<IfModule mod_rewrite.c>
RewriteEngine On
#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
</IfModule>

codeigniter 404 on existing controller

I am facing a different problem in codeigniter.
When I try to access the videos page in my site, it will redirect to 404.shtml page. But cvideos.php file exists in my controllers folder.
If I access like this http://domain-name/videos , then it will be redirected like this
//domain-name/500.shtml
And If I access the same page like this //domain-name/videos/myvideos, then then it will be redirected like this
//domain-name/404.shtml
Also, If I change the controller name from videos to some other name like videoss it works fine. Can anyone tell wats the issue.
I used this line in my .htaccess also just for testing. But no use.
RewriteRule ^videos/$ index.php/videoss/ [L]
Your controller needs to be the same name as the class it contains.
hence -
<?php
controller Videos extends Controller {
/* bla */
}
?>
should be saved as:
videos.php in the "controllers" directory.
Nothing else will work.
also your rewrite rule has two "s"'s, but that might be intentional.
and it looks like what you are trying to do with .htaccess can be achieved with CI's routing
Edit: .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
#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
</IfModule>
please note I did not create this - it was found by scouring the CI forums. It's a rather thorough htaccess however.
Don't forget to set the value of "index.php" to "" in your config.
base_url is case sensitive
localhost/site/controller = c:...\site
localhost/SITE/controller = c:...\SITE
make sure you are not missing .htaccess file in your root directory. Or check for its accuracy. Make sure uri_protocol and base_url are set correctly in config.php.
for sample, i am copying my .htaccess file here
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_dir
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I used this to get rid of index.php in url.
I had a similar problem when transferring a CI site from WAMPP to a LAMPP that someone else had made. It would seem that WAMPP was configured to be case-insensitive, as when I converted all my controller/model/view file names and all php strings containing controller/model/view names to lowercase it worked perfectly.

Resources