系统环境Debian8 apache2 php5.6 mysql5.5
1.在/etc/apache2/apache2.conf中写入需要隐藏index.php的项目的绝对路径,在这里我的路径为/var/www/html/thinkdevice 添加如下的配置:
我这里的index.php 没有放在项目内的public目录下,而是项目目录的根目录
<Directory /var/www/html/thinkdevice >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
2.在/etc/apache2/apache2.conf 中引入mod_rewrite.so ,我这里使用绝对路径,版本不一样的话,文件位置可能不同。
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
debian8环境下,mod_rewrite.so位置是 /usr/lib/apache2/ 目录下
3.在项目的目录内index.php同级目录下,即项目的根目录下,编辑文件.htaccess
如下填写:
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
4.如图所示,这样的配置可以实现隐藏index.php 但同时不会带来css和js引用失效的问题,网上有些教程会导致css和js失效无法引用