环境:Ubuntu 16.04 64bit ,Apache2.4.18 PHP 5.6
1、修改/etc/apache2/apache2.conf ,将AllowOverride None改为AllowOverride All
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
2.
cd /etc/apache2/mods-enable
ln -s ../mods-avaiable/rewrite.load rewrite.load
在项目根目录下添加.htaccess文件,修改rewrite规则
RewriteEngine on
#不显示index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
重启apache2
sudo /etc/init.d/apache2 restart
没有rewrite之前链接是这样的
https://localhost/tp/index.php/Home/Datas
rewrite之后链接是这样的
https://localhost/tp/Home/Datas
省去了index.php