2015-07-09 170 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