ThinkPHP URL 重定向

想要去掉index.php, 由于全部地址都带着这个显得太长了。php

步骤以下:shell

一、修改apache的配置文件httpd.confapache

    打开putty,执行以下命令vim

vim /etc/httpd/conf/httpd.conf
i  //进入编辑模式
/mod_rewrite.so //执行查找命令,将加载模块前的#去掉
/AllowOverride  //执行查找命令,AllowOverride None 将None改成 Al
esc :wq //保存退出
vim .htaccess //进入index.php 同级目录,建立.htaccess,使用vim命令便可建立和编辑文件,.htaccess是隐藏文件,在xftp和putty下面使用ls命令都是看不到的。
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
粘贴上面的语句,保存退出
service httpd restart 重启apache

执行不带index.php 的连接,看可否正确显示,若是能够则进行下一步ide

二、上一步虽然去掉index.php能够正确访问了,可是使用U函数自动生成的连接仍是带有index.php    函数

    须要修改 config.php测试

vim Application/Common/Conf/config.php
在配置参数中添加
'URL_MODEL' =>2,

测试成功,ok
url

下次使用url规则,继续简化rest

相关文章
相关标签/搜索