2016-01-11 44 views
0

我正在使用CodeIgniter。我想從url中刪除index.php部分。 我正在使用CentOS。CodeIgniter htaccess 403

我的Apache的配置是:

<Directory "/var/www/html"> 
Options Indexes FollowSymLinks MultiViews 
AllowOverride All 
Require all granted 
</Directory> 

我的文件位於: 的/ var/www/html等/項目/網站/ 那麼該URL: example.com/project/site/

我的htaccess是:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

這來自官方的wiki。

我用Site類創建了一個Site.php控制器。 如果我訪問example.com/project/site/site加載頁面,但CSS和img文件(位於views/template /中)不會加載,因爲403權限被拒絕錯誤。

但是,如果我改變了AllowOverride所有的AllowOverride None,然後我去: example.com/project/site/index.php/site

它的工作原理,所以對文件的權限都OK。

順便說一句,這是我的config.php文件:

$config['base_url'] = 'http://ipserver/project/site/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

SOLUTION

添加滿足任何在配置的httpd文件似乎工作。

+0

如何你指的是你的資產?什麼是你的資產的路徑? – Kisaragi

+0

在視圖中我有一個模板文件夾,與CSS,JS和其他子文件夾。另外我還有頁面,其中有頁面的主要html。在這個頁面中,我把這個: <?php echo $ base_url; ?>/images/bg/1.jpg 來自:$ data ['base_url'] = base_url('/ application/views/template /'); corse,這是控制器。 – mt19

回答

0

按照下列步驟:

  1. 更改配置文件是這樣的:

    $配置[ 'index_page'] = '';
    $ config ['uri_protocol'] ='AUTO';

  2. 使用下面的.htaccess:

RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]

注:的.htaccess取決於服務器。我有些服務器(例如:Godaddy的)需要使用下面的.htaccess:

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

來源鏈接:https://www.linkedin.com/groups/109912/109912-5948862618142785540

+0

不幸的是,這是行不通的。我仍然有403個錯誤。我應該將che htaccess放在框架的根目錄還是放在服務器的根目錄下? 我有一個專用的服務器 – mt19

+0

@ mt19根框架 – Dray

+0

@Dray這是結果:http://37.187.6.125/project/fattoriabesana/frame/與在框架根目錄htaccess 順便說一句,這是方法: http://37.187.6.125/project/fattoriabesana/frame/site 這是另一個頁面: http://37.187.6.125/project/fattoriabesana/frame/site/shop 作爲你可以看到,模板目錄 – mt19