操作步骤
- 启动
mod_rewrite
sudo a2enmod rewrite
- 修改
/etc/apache2/apache2.conf
(ubuntu16.04后没有httpd.conf
文件,配置文件是apache2.conf
)文件,主要是AllowOverride None
改为AllowOverride All
<Directory />
Options FollowSymLinks
AllowOverride All
#Require all denied
</Directory>
- 在项目根目录下新建一个名为
.htaccess
文件,添加如下内容
<IfModule mod_rewrite.c>
RewriteEngine on
#不显示index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
- 重启Apache
sudo /etc/init.d/apache2 restart