CI 框架(Apache环境)有效删除URL中的index.php 分类: CI框架 php 2014-01-20 13:17 266人阅读 评论(0) 收藏

【转载自】http://codeigniter.org.cn/forums/thread-15444-1-1.html


index位于根目录时,你可以在index.php所在的根目录里新建.htaccess文件并使用以下代码:

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]


如果需要访问index.php同级目录下的js,css和images,需要在index.php所在的根目录里新建.htaccess文件并使用以下代码:

RewriteEngine On
RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

当index.php不在根目录时,你可以在index.php所在目录里新建.htaccess文件并使用以下代码:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L]

注意把path_to_app换成你的index.php所在文件的目录.假设你的index.php放在根目录的tool子文件夹下,你可以这样写:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /tool/index.php?/$1 [L]


以上方法在使用facebook第三方登录的时候会无法访问到facebook php sdk的某些文件,需要将.htaccess文件全部重写成以下形式:


RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|cab|rar|html|pdf|zip|xml|doc|tiff|deb|dmg|exe|tgz|flv|mp4|apk|pkg|mov)$ index.php [NC]


<IfModule mod_php5.c>
php_value upload_max_filesize  300M
php_value post_max_size        300M
php_value emax_file_uploads    300

php_value gc_maxlifetime  3600*24*30
</IfModule>


版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-01-20 13:17  snow_finland  阅读(184)  评论(0编辑  收藏  举报