apache配置rewrite规则,删除url中的index.php

来源:互联网 发布:js div 左右滑动 编辑:程序博客网 时间:2024/06/05 06:35

1,在httpd.conf文件中配置如下部分

<VirtualHost *:81>
DocumentRoot D:/Source/v5 
</VirtualHost>

改成

<VirtualHost *:81>DocumentRoot D:/Source/v5 # Turn on URL rewritingRewriteEngine OnRewriteRule ^/app/(.*)$ /index.php/app/$1 [L,NC] RewriteRule ^/api/(.*)$ /index.php/api/$1 [L,NC] RewriteRule ^/open/(.*)$ /index.php/open/$1 [L,NC] RewriteRule ^/admin/(.*)$ /index.php/admin/$1 [L,NC] </VirtualHost>


RewriteRule ^/app/(.*)$ /index.php/app/$1 [L,NC] 

意思将所有http://domain/app/controller  的url重写为 http://domain/index.php/app/controller。

L(last rule) 表明当前规则是最后一条规则,停止分析以后规则的重写。

NC(no case) 不区分大小写。

2,重写规则既可以在apache配置里写,还可以在kohana的.htaccess文件里写。

另外在项目目录下面的conf/routes.php中也可以配置url替换规则。


原创粉丝点击