1.首先启动mod_rewrite
终端输入:sudo a2enmod rewrite
2.更改/etc/apache2/apache2.conf(ubuntu16.04没有httpd.conf文件,配置文件是apache2.conf)文件,主要是 AllowOverride None 改为AllowOverride All
3.在项目根目录下新建一个.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>
4.重启Apache
service apache2 restart