【问题标题】:MVC Code Igniter 403 ErrorMVC 代码点火器 403 错误
【发布时间】:2014-02-21 09:49:58
【问题描述】:

大家好,我是 MVC 新手,在尝试 mod_rewrite 后,当我尝试加载 site/about 时遇到了 403 问题。我的项目位于我的网络服务器htdocs 的主根目录中,我一直在努力理解许多在线教程。错误是;

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while 
trying to use an ErrorDocument to handle the request.

站点 - 控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {

public function index()
{
    $data['title']= "Welcome Learn Guitar Online";
    //$this->load->view('home',$data);
    //$this->getValues();
    $this->load->view("about",$data);

}
}

关于.php

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $title; ?></title>

</head>
<body>

<div id="container">
<h1>Welcome to about</h1>
<div id="body">
    <p>hello</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

</body>
</html>

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

配置文件变量

$config['base_url'] = 'localhost/index.php';
$config['index_page'] = '';

【问题讨论】:

    标签: php codeigniter mod-rewrite http-status-code-403 codeigniter-routing


    【解决方案1】:

    您正在尝试加载site/about。但正如我看到您的代码,没有名为about 的函数。你只需要调用你的控制器,即http://localhost/FOLDER_NAME/site,默认它会调用index函数并加载about.php视图。

    你的config.php应该是这样的

    $config['base_url'] = 'http://localhost/FOLDER_NAME';
    $config['index_page'] = '';
    

    如果您已将 ht.access 放在项目文件夹中,则无需再定义 base_url()

    【讨论】:

      【解决方案2】:

      你能不能试着把.htaccess 改成这个

      <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /FOLDER_NAME/
          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>
      

      Config

      $config['base_url'] = 'http://localhost/FOLDER_NAME';
      $config['index_page'] = '';
      

      将 FOLDER_NAME 替换为您的文件夹名称。现在你应该可以在没有 index.php 的情况下访问你的 url

      【讨论】:

        猜你喜欢
        • 2012-02-21
        • 2016-03-15
        • 2011-09-27
        • 2016-01-13
        • 2015-12-05
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多