2015-07-09 130 views
1

我試圖從我的CodeIgniter 3 URL刪除index.php。目前,所有我的URL看起來像這樣:從CodeIgniter 3 URL刪除index.php

http://example.com/index.php/Controller/function 

而且我希望他們看起來像這樣:

http://example.com/Controller/function 

我已經在的下面的文章和堆棧溢出後,卻沒有跟着一起我已經找到答案,爲我工作:

我的目錄結構設置如下:

  • 在/ var/WWW /例如
    • /應用
      • (標準的CodeIgniter應用程序文件...控制器,模型意見,CONFIGS)
    • /公共
      • /CSS
      • /JS
      • /字體
      • /圖像
      • 的index.php
      • 的.htaccess
    • /系統
      • 我沒碰過此目錄中的任何內容
    • 的.htaccess

/var/www/example/.htaccess的內容:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^$ public/ [L] 
    RewriteRule (.*) public/$1 [L] 
</IfModule> 

/var/www/example/public/.htaccess內容:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php/$1 [QSA,L] 
</IfModule> 

/var/www/example/application/config/config的內容。PHP(修剪基於之前讀什麼我已經改變):

sudo a2enmod rewrite 
sudo service apache2 restart 

這個網站我的虛擬主機文件是:

$config['base_url'] = ''; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; /* have tried AUTO as well */ 

對於我的Apache服務器,國防部重寫已通過啓用:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName example.com 
    ServerAlias www.example.com 
    DocumentRoot /var/www/example/public 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

回答

1

將這些添加到您的虛擬主機文件並根據需要調整Options指令。

<Directory /> 
      AllowOverride All 
      Order allow,deny 
      allow from all 
    </Directory> 

    <Directory "/var/www/example/public"> 
      AllowOverride All 
      Order allow,deny 
      allow from all 
    </Directory> 
+0

謝謝!這工作完美! – acamp120