且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CodeIgniter错误403

更新时间:2023-02-09 08:06:37

codeigniter的安装非常简单

The installation of codeigniter is very simple

  1. 解压缩软件包.
  2. 将CodeIgniter文件夹和文件上传到您的服务器.通常,index.php文件将位于您的根目录.
  3. 使用文本编辑器打开application/config/config.php文件并设置基本URL.如果您打算使用加密或会话,请设置 您的加密密钥.
  4. 如果要使用数据库,请使用文本编辑器打开application/config/database.php文件并设置您的 数据库设置.
  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.

从文档 https://codeigniter.com/user_guide/installation/index.html

在您的application/config/config.php中进行如下设置

in your application/config/config.php make setting like this

$config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'] .'/your_project/'; 

完成后,访问您的网站

http://localhost/your_project/index.php

仅此而已

如果您想访问自己的控制器

If you want to access your own controller

http://example.com/[controller-class]/[controller-method]/[arguments]

示例:

http://example.com/your_project/index.php/your_controller

要删除index.php,请编辑.htaccess

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>