Home  >  Article  >  Web Front-end  >  CI 框架(Apache环境)有效删除URL中的index.php_html/css_WEB-ITnose

CI 框架(Apache环境)有效删除URL中的index.php_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 08:47:191106browse

CI 框架(Apache环境)有效删除URL中的index.php

http://www.xuebuyuan.com/2172044.html

http://codeigniter.org.cn/forums/thread-15444-1-1.html

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

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

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

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

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

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

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

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

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

RewriteEngine onRewriteRule !\.(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  300Mphp_value post_max_size        300Mphp_value emax_file_uploads    300php_value gc_maxlifetime  3600*24*30</IfModule>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn