CodeIgniter error 403 - php

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>

Related

CodeIgniter - Mod_Rewrite on One.com hosting service

I'm really starting to regret buying a domain at One.com
I have a simple CI project set up that works perfectly on localhost, but one.com isn't my friend. I can't seem to get mod_rewrite working. I don't even bother contacting support, because I'm getting the feeling that anyone who needs more than an index page isn't welcome there.
This is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /luc/
#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|img|js|UberGallery|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>
And in CI config:
$config['base_url'] = '';//I have tried the full URI.
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //I have tried REQUEST_URI as well.
luc is a subdomein of my domain, hence the RewriteBase in .htaccess.
In all my subfolders, I have an .htaccess file with deny from all.
This seems to be a one.com specific issue, so I hope there's someone experienced enough to spot an error in my setup.
What am I doing wrong?

Clicking on flash in CodeIgniter is loading 404 error view page instead of the hard-coded URL in flash file

If I use clicktag param it works fine, but when the flash file is not using clicktag, it goes wrong and codeigniter tries (after click on the banner) load some url like:
http://mywebsite.com/hardcodedaddressinflash.com
instead of just:
http://hardcodedaddressinflash.com
If it is in plain html or php file (not using CodeIgniter) it works great.
I guess I have to set something for swf files in codeigniter’s .htaccess to go directly where the hard-coded URL points, but how?
Any advice?
I have tried swgobject and also direct embed swf code, but all are giving the same result.
But somehow if I am using clicktag it work fine. I do not understand at all.
EDIT: my .htaccess file looks like this:
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

codeigniter: why is that everytime i set a specific routing rule that page's css/js don't get loaded?

I'm building my website in codeigniter, and here an example of a routing rule that's giving me some trouble:
$route['updategamepage/(:num)'] = 'maincontroller/main/updategamepage/$1';
So is there anything wrong with the format/structure of the rule? Here is an example url that uses that rule:
http://www.mydomain.com/ci_website/updategamepage/6
and when that page gets loaded, the css/js don't get loaded with the page...any idea on whats going wrong?
Your routing rule should only apply to things that get routed through CodeIgniter's index.php file. That routing is dictated by the application's .htaccess file. It's possible that your htaccess is redirecting requests to your .css file to CodeIgniter when you don't want it to.
Ultimately you may way to check your web server logs, including potentially enabling mod_rewrite logging, to see what's actually going on.
Here is an example .htaccess that I use for my CodeIgniter apps:
(Notice you will have to change the RewriteBase directive near the top)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/
#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>
Here's a short .htaccess snippet I always use in my projects, it's much easier to understand.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
what it does is that it redirects every url that doesn't contain index.php, assets, shared, uploads and robots.txt right after the URL to your public folder to your index.php file allowing you to set your $config['index_page'] value to '', that will make your URL's much more pleasant for the eye and search engines. Without this you had URL's like http://www.mysite.com/index.php/pages/about, with it you will have http://www.mysite.com/pages/about.
Personally I keep my JS and CSS files in assets folder, but if you like to keep them in the root folder, simply add their folder names to the second line of the .htaccess file I provided separated with a | sign
RewriteCond $1 !^(index\.php|js|css|shared|uploads|robots\.txt)
As I suggested in my answer to your other question a few minutes ago, you better erase the contents of your $config['base_url'] value and let CodeIgniter do the job for you - he does it really well.

Codeigniter htaccess - controllers in subfolder not working

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.*

codeigniter 404 error

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>

Categories