php CodeIgniter 错误 403
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37510478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter error 403
提问by Slim Shady
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.
我是一个完整的 CodeIgniter 初学者,一般来说是框架,我尝试过 Laravel 和 CakePHP,但两者都安装起来非常复杂(对我来说)所以现在我已经下载了 CI,它看起来很简单,除了这个拒绝访问错误。
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.
该错误是默认的 Firefox 403(访问被拒绝)错误。它说:
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
这发生在我去的时候 localhost/codeigniter/application
My base URL: http://localhost/codeigniter/application
. I don't know why I set it like that but it seemed logical.
我的基本网址:http://localhost/codeigniter/application
。我不知道为什么我这样设置,但这似乎合乎逻辑。
UPDATE:After I edit the htaccess file to make it look like this: ` RewriteEngine On
更新:在我编辑 htaccess 文件使其看起来像这样之后:` RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.PHP/ [L]
, it gave me another 403 error (which isn't the default Firefox error) and it simply says "Directory access is forbidden".
,它给了我另一个 403 错误(这不是默认的 Firefox 错误),它只是说“禁止访问目录”。
回答by Fil
The installation of codeigniter is very simple
codeigniter的安装很简单
- 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.
- 解压缩包。
- 将 CodeIgniter 文件夹和文件上传到您的服务器。通常 index.php 文件将位于您的根目录。
- 使用文本编辑器打开 application/config/config.php 文件并设置您的基本 URL。如果您打算使用加密或会话,请设置您的加密密钥。
- 如果您打算使用数据库,请使用文本编辑器打开 application/config/database.php 文件并设置您的数据库设置。
from the documentation https://codeigniter.com/user_guide/installation/index.html
来自文档https://codeigniter.com/user_guide/installation/index.html
in your application/config/config.php make setting like this
在您的 application/config/config.php 中进行这样的设置
$config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'] .'/your_project/';
once your done, access your website at
完成后,访问您的网站
http://localhost/your_project/index.php
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:
例子:
to remove index.php, edit your .htaccess
要删除 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?/ [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?/ [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>