【问题标题】:CodeIgniter error 403CodeIgniter 错误 403
【发布时间】:2016-05-29 13:30:01
【问题描述】:

我是 CodeIgniter 的初学者,一般来说是框架,我尝试过 Laravel 和 CakePHP,但安装起来都非常复杂(对我来说),所以现在我已经下载了 CI,它看起来很简单,除了访问被拒绝错误。

该错误是默认的 Firefox 403(拒绝访问)错误。它说: You don't have permission to access the requested object. It's either read-protected or not readable by the server.

当我转到localhost/codeigniter/application时会发生这种情况

我的基本网址:http://localhost/codeigniter/application。我不知道为什么我这样设置它,但它似乎合乎逻辑。

更新:在我编辑 htaccess 文件使其看起来像这样之后: ` 重写引擎开启

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.PHP/$1 [L]    

,它给了我另一个 403 错误(这不是默认的 Firefox 错误),它只是说“目录访问被禁止”。

【问题讨论】:

  • 我做到了,而且效果很好。但我想做的是进入“应用程序”目录。
  • 不能这样,一定是http://example.com/[controller-class]/[controller-method]/[arguments]方式
  • application 目录不应通过浏览器访问。将您的 BASEURL 更改为 $config['base_url'] = 'http://localhost/codeigniter/'。 >我不知道为什么我这样设置,但它似乎合乎逻辑。作为“完整的初学者”(您的参考),您应该遵循的唯一逻辑是阅读完整的documentation(如果需要,几次)。

标签: php codeigniter


【解决方案1】:

codeigniter的安装很简单

  1. 解压包。
  2. 将 CodeIgniter 文件夹和文件上传到您的服务器。通常 index.php 文件会在你的根目录下。
  3. 使用文本编辑器打开 application/config/config.php 文件并设置您的基本 URL。如果您打算使用加密或会话,请设置 您的加密密钥。
  4. 如果您打算使用数据库,请使用文本编辑器打开 application/config/database.php 文件并设置您的 数据库设置。

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

在您的 application/config/config.php 中进行这样的设置

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

完成后,访问您的网站

http://localhost/your_project/index.php

就是这样

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

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

例子:

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

要删除 index.php,请编辑您的 .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>

【讨论】:

  • 还有那个错误。 “目录访问被禁止”。
  • 您使用的是什么服务器以及如何访问它?
  • 我正在使用 XAMPP。我不知道“你是如何访问它的”是什么意思,但我总是通过“localhost”访问它。很抱歉不太清楚
  • 它工作的家伙。我去了`localhost/codeigniter/index.php/pages/view`,它工作了。
猜你喜欢
  • 1970-01-01
  • 2017-03-23
  • 2015-05-07
  • 1970-01-01
  • 2018-10-24
  • 1970-01-01
  • 1970-01-01
  • 2015-10-06
  • 2023-03-05
相关资源
最近更新 更多