做Url路由美化时我们都不会在Url显示脚本文件(index.php),这需要Apache启用 Rewrite 伪静态功能来实现;
demo.com/index.php/site/index 应美化为 demo.com/site/index
下面是配置过程:
1. 打开apache的配置文件:httpd.conf;
2. 找到#LoadModule rewrite_module modules/mod_rewrite.so,去掉前面的#号,开启mod_rewrite模块;
3. 找到 AllowOverride 配置项,把值由“NONE”改为“ALL”,需要更改两个地方;
4. 在网站访问目录下(也就是index.php的同级目录)新建文件:.htaccess
5. 把下面的内容放入 .htaccess 文件中:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
6. 重启apeche就可以了