CodeIgniter error 403

2020-02-07 13:02发布

问题:

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

回答1:

The installation of codeigniter is very simple

  1. Unzip the package.
  2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
  3. 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.
  4. 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>