我正在尝试从我的CodeIgniter 3网址中删除index.php。目前,我的所有网址都是这样的:
http://example.com/index.php/Controller/function
我希望他们看起来像这样:
http://example.com/Controller/function
我已经关注了以下文章和Stack Overflow帖子,但我找到的答案都没有对我有用:
我的目录结构设置如下:
/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>
答案 0 :(得分:2)
将这些添加到虚拟主机文件中,并根据需要调整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>