Home > php教程 > php手册 > CI 框架(Apache环境)有效删除URL中的index.php

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

WBOY
Release: 2016-06-06 19:57:35
Original
959 people have browsed it

index位于根目录时,你可以在index.php所在的根目录里新建.htaccess文件并使用以下代码: RewriteEngine onRewriteCond $1 !^(index\.php|robots\.txt)RewriteRule ^(.*)$ /index.php?/$1 [L] 如果需要访问index.php同级目录下的js,css和images,需要在index.


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

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


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

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

当index.php不在根目录时,你可以在index.php所在目录里新建.htaccess文件并使用以下代码:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L]
Copy after login

注意把path_to_app换成你的index.php所在文件的目录.假设你的index.php放在根目录的tool子文件夹下,你可以这样写:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /tool/index.php?/$1 [L]
Copy after login


以上方法在使用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>
Copy after login


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template