1

大家都好我是新來的MVC,並試圖一mod_rewrite的我有麻煩當我試圖加載site/about後。我在我的Web服務器htdocs的主根目錄中有我的項目,我一直在努力去理解許多在線的教程。錯誤是;MVC代碼點火器403錯誤

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); 

} 
} 

about.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'] = ''; 

回答

0

你能嘗試使.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了

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()也。