thinkphp去掉链接上带的index.php
在用thinkphp链接的时候,它会自动带上入口文件index.php,导致链接变得很难看。 例如:http://localhost/index.php/Home/index/index
不过没关系,我们可以去掉它。
- Apache
如果是Apache启动的程序的话,在入口文件(也就是Index.php所在)的同级添加.htaccess文件,内容如下:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>
然后就可以去掉Index.php了 如:http://localhost/index.php/Home/index/index
- Nginx
如果是Nginx启动的程序的话,在nginx的配置文件nginx.conf中加入一个if判断。
location / {if (!-e $request_filename){ //添加的代码 rewrite ^/(.*)$ /index.php/$1 last;}}