【发布时间】:2015-09-28 12:05:36
【问题描述】:
我正在尝试从我的 CodeIgniter 3 URL 中删除 index.php。目前,我所有的 URL 都是这样的:
http://example.com/index.php/Controller/function
我希望它们看起来像这样:
http://example.com/Controller/function
我关注了以下文章和 Stack Overflow 帖子,但我找到的答案都没有对我有用:
- https://www.codeigniter.com/userguide3/general/urls.html
- How to remove "index.php" in codeigniter's path
我的目录结构设置如下:
- /var/www/example
- /应用程序
- (标准 CodeIgniter 应用程序文件...控制器、模型、视图、配置)
- /公共
- /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 的内容(根据我之前的阅读内容进行了修改):
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; /* have tried AUTO as well */
对于我的 Apache 服务器,mod-rewrite 已通过以下方式启用:
sudo a2enmod rewrite
sudo service apache2 restart
我的这个网站的虚拟主机文件是:
<VirtualHost *:80>
ServerAdmin myemail@example.com
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>
【问题讨论】:
标签: apache .htaccess codeigniter