Ive started a codeigniter site. my default controller is $route['default_controller'] = "login"; in routes.php
and my base URL is $config['base_url'] = 'http://digimed.net/sandbox/'; in config.php
Scenario A
I type http://digimed.net/sandbox/ in teh URL bar I get the index method of the login controller as expected.
Scenario B
I type something like http://digimed.net/sandbox/login I get a 404 error when I expected the same result as in scenario A.
In fact I cannot access any function in the login controller. I get a 404 error every time.
Is there something I need to change in routes or congig?
thanks
in case anyone is interested I solved the problem by adding the following .htaccess file in the website route directory ( where the codeigniter route directory lives )
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /system_admin
#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)
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
I'm a complete beginner in CodeIgniter, Frameworks in general, and I tried Laravel and CakePHP but both are very complex to install (for me) so now I've downloaded CI and it looks pretty simple except for this access denied error.
The error is the default Firefox 403(access denied) error. It says:
You don't have permission to access the requested object. It's either read-protected or not readable by the server.
This happens when I go to localhost/codeigniter/application
My base URL: http://localhost/codeigniter/application. I don't know why I set it like that but it seemed logical.
UPDATE: After I edit the htaccess file to make it look like this:
` RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.PHP/$1 [L]
, it gave me another 403 error (which isn't the default Firefox error) and it simply says "Directory access is forbidden".
The installation of codeigniter is very simple
Unzip the package.
Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set
your encryption key.
If you intend to use a database, open the application/config/database.php file with a text editor and set your
database settings.
from the documentation https://codeigniter.com/user_guide/installation/index.html
in your application/config/config.php make setting like this
$config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'] .'/your_project/';
once your done, access your website at
http://localhost/your_project/index.php
That's all
If you want to access your own controller
http://example.com/[controller-class]/[controller-method]/[arguments]
Example:
http://example.com/your_project/index.php/your_controller
to remove index.php, edit your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /your_project/
#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]
</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>
Ive been using codeigniter CMS. It was working fine...until 4 days. I did play a bit with httpd.conf but it has .htaccess enabled and all so I am sure it might not be the problem . Whenever I click any page from home page of CMS it redirects to base_url.The login page of CMS appears fine and also logs into home page. The urls in the home page redirects to base URL.
Ive checked this question
CodeIgniter all the pages redirecting to home page?
Tried this solution by changing $config['uri_protocol'] = "AUTO" to options mentioned. But it doesn't seem to be the solution. My .htaccess file reads
DirectoryIndex index.php
<IfModule mod_rewrite.c>
#http://codeigniter.com/wiki/mod_rewrite
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>
Tried playing with config.php by changing base_url and all..but it doesn't seem to work. Any idea/help ?
I am new to CI and don't know much about rewrite rules. I was able to find htaccess rules from stackoverflow post which allows me to remove index.php from the URL. The ht access rules are as following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /siebeluigen/
#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>
But this doesn't work if I move my controllers to subfolder within the controller directly. for example
If I put my Application controller in following path
application/controllers/application.php
Then I can access it from URL
http://localhost/siebeluigen/application
But if my directory structure is
application/controllers/app/application.php
Then I get error with following url
http://localhost/siebeluigen/app/application
but it works like this
http://localhost/siebeluigen/index.php/app/application
So, I am pretty sure there is something in htaccess that I should be able to change to make it work.
Please help!!!
Update
My htaccess file was in the application folder instead of root. Moving the file to the folder were index.php is located solved the issue. I have marked the answer that is working.
Thanks...
This is my htaccess file that I use on ALL my projects:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
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>
Then - also make sure that inside your config.php file
$config['index_page'] = '';
edit: you NEVER want to point someone to your application folder - you ALWAYS point them to your index.php - EVERYTHING goes through Index.php - and it does the re-routing to where it is needed.
This is the condition that is usually meant to redirect to application.php
RewriteCond %{REQUEST_URI} ^application.*
app/application doesn't match this condition. Try changing it to this:
RewriteCond %{REQUEST_URI} ^app/application.*
I have made a codeIgniter application. Its working oh so cool on my local, but when I deploy it to the main, all my pages are getting redirected to the home page.
I have the following directory structure:
---www
-----.htaccess
------codeIgniter (the application lives here).
My htaccess reads as follows
RewriteEngine on
RewriteCond $1 ^media
RewriteRule ^(.*)$ codeIgnite/$1
RewriteCond $1 !^(index\.php|codeIgnite|images|robots\.txt)
RewriteRule ^(.*)$ codeIgnite/index.php/$1
And this is my config.php
$config['base_url'] = "http://localhost/codeIgnite/"; // or should it just be http://localhost/ ?
Is there some other config settings I need to change ? Please help.
My home page shows up just fine. Problem is with other pages. No matter what URL I give, I see my home page UI.
Setting the $config['uri_protocol'] = "ORIG_PATH_INFO", fixed the issue.
I've used the provided .htaccess from CodeIgniter and just set the RewriteBase to my subdirectory to get it to work properly.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeIgnite/
#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>
You should have to put the .htaccess in the CodeIgniter folder and also you have to modify the last line of your file to this
RewriteRule ^(.)$ /codeIgniter/index.php/$1 or
RewriteRule ^(.)$ /codeIgnite/index.php/$1
You dont have to do nothing in apache config only turn on the extension rewrite_module
I'm new to CodeIgniter and routing.
I have a Login controller whose index() loads up a view to enter a username/password. In the view, the form has action="login/authenticate". Login->authenticate() determines if the login is valid or not. If it's valid, redirect('lobby'), if not redirect('login')
routes.php:
$route['default_controller'] = "login"
config.php:
$config['base_url'] = "http://localhost/dts/";
$config['index_page'] = "index.php";
The problem is that when i go to http://localhost/dts/ , click login, I am correctly (?) redirected to http://localhost/dts/login/authenticate but the browser says Object not found!. But when I go to http://localhost/dts/index.php/ (with trailing slash), it works correctly (I get redirected to http://localhost/dts/index.php/login/authenticate, and am logged in)
I tried removing "index.php" by using a .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and it would no longer open even the http://localhost/dts/
I'm confused.. what's going on?
The issue is with the last line of your .htaccess file.
Since your application is in a subdirectory ("dts"), the forward slash in front of the "index.php" won't work. Try removing it so that your file looks like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Follow this article on the CodeIgniter wiki to properly setup your .htaccess 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]
#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>
Did you change this in your config:
$config['index_page'] = "index.php";
To this:
$config['index_page'] = "";
Also, read this post by Jamie Rumbelow:
http://jamieonsoftware.com/blog/entry/the-best-codeigniter-.htaccess
Thats the .htaccess I've always used and it works great for me.