㈠ CI框架如何刪除URL中index.php的終極解決方案
默認情況下,index.php 文件將被包含在你的 URL 中:
example.com/index.php/news/article/my_article
你可以很容易的通過 .htaccess 文件來設置一些簡單的規則刪除它。下面是一個例子,使用「negative」方法將非指定內容進行重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
注意:如果你的項目不在根目錄請把上面這一句改為:RewriteRule ^(.*)$ index.php/$1 [L]
在上面的例子中,可以實現任何非 index.php、images 和 robots.txt 的 HTTP 請求都被指向 index.php。
我的終極解決方案
但在實踐中,以上方案僅適用於與運行於Apache環境下的伺服器且並不具有充分的普遍適用性!當CI程序位於非根目錄或位於某些虛擬主機上時,以上解決方案會引起」404錯誤」或」no input file specified」等錯誤.網路參考過相關問題的解放方案後,找到了一種具有通用性的有效刪除URL路徑中index.php的方法,代碼參考如下:
index位於根目錄時,你可以在index.php所在的根目錄里新建.htaccess文件並使用以下代碼:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
當index.php不在根目錄時,你可以在index.php所在目錄里新建.htaccess文件並使用以下代碼:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L]
注意把path_to_app換成你的index.php所在文件的目錄.假設你的index.php放在根目錄的tool子文件夾下,你可以這樣寫:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txtl)
RewriteRule ^(.*)$ /tool/index.php?/$1 [L]
以上方案應該可以解決Apache環境下如何有效刪除URL中index.php的問題,
㈡ php怎麼辦url中的index.php去掉
為美觀一些,去掉CI默認url中的index.php。分三步操作:
1.打開apache的配置文件,conf/httpd.conf :
LoadMole rewrite_mole moles/mod_rewrite.so,把該行前的#去掉。
搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關.htaccess的該行信息改為AllowOverride All。
2.在CI的根目錄下,即在index.php,system的同級目錄下,建立.htaccess,直接建立該文件名的不會成功,可以先建立記事本文件,另存為該名的文件即可。內容如下(CI手冊上也有介紹):
RewriteEngine on
RewriteCond $1 !^(index/.php|images|robots/.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目錄下,例如我的是:http://localhost/CI/index.php/,第三行需要改寫為RewriteRule ^(.*)$ /CI/index.php/$1 [L]。
另外,我的index.php的同級目錄下還有js文件夾和css文件夾,這些需要過濾除去,第二行需要改寫為:RewriteCond $1 !^(index/.php|images|js|css|robots/.txt)。
3.將CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";將$config['index_page'] = ""; 。
ok,完成。還要記得重啟apache。
㈢ 如何隱藏url中的index.php
第一步:'URL_MODEL'=>'2',
第二步:根路徑下建立一個.htaccess,可以通過一些軟體比如EditPlus去另存為,windows可能不能直接創建
第三步:
<IfMole mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfMole>
放到.htaccess中保存
第四步開啟Apache rewrite 模式 去配置文件中#LoadMole rewrite_mole moles/mod_rewrite.so 去掉前面的#,AllowOverride None改為AllowOverride All ok
當然如果你不是Apache 是IIS就不能這樣配了
㈣ 部分網站url中index.php自動隱藏是如何實現的
根目錄下新建立一個配置文件,命名為: .htaccess
在裡面這樣寫:
RewriteEngineon
RewriteCond$1!^(index.php|images|robots.txt)
RewriteRule^(.*)$/index.php/$1[L]
就可以去掉 index.php 了。要注意 /index.php/$1 要根據你目錄(Web 目錄,比如 http://www.domain.com/index.php)的實際情況來定,比如網站根目錄是 /ci/index.php 則要寫成 /ci/index.php/$1
RewriteCond$1!^(index.php|images|robots.txt)
上面的代碼意思是排除某些目錄或文件,使得這些目錄不會 rewrite 到 index.php 上,這一般用在圖片、js、css 等外部資源上。也就是說非 PHP 代碼都要排除出去。(這里我排除了 images 目錄和 robots.txt 文件,當然 index.php 也應該被排除)
哦,對了,還要修改 config.php 這個文件中的下列內容:
/*
|--------------------------------------------------------------------------
|IndexFile
|--------------------------------------------------------------------------
|
|Typicallythiswillbeyourindex.phpfile,unlessyou'verenameditto
|somethingelse.Ifyouareusingmod_rewritetoremovethepagesetthis
|variablesothatitisblank.
|
*/
$config['index_page']="index.php";
把其中的 "index.php" 改成 "" 就可以了。
㈤ CI如何取消二級目錄里的index.php呀
修改htaccess這個我修改了的,文檔的操作方式貌似只對根目錄訪問的方式有效,對於二級欄目無效
㈥ 自己寫寫框架 怎麼隱藏 index.php,和修改URL的路徑問題
看伺服器的支持了,一般的apache的支持Rewrite重寫,就是用.htaccess文件來重寫路徑。
比如:/index.php?m=123&h=456
可以重寫成:
/123/456
nginx的語法和apache的不同。
windows下iis的語法也不同。
㈦ 在nginx下如何去除ci框架url中的index.php
ci框架默認的url規則中帶有應用的入口文件,例如:
example.com/index.PHP/news/article/my_article
在以上URL中帶有入口文件index.php,這樣的URL規則對搜索引擎來說是不友好的,那麼如何去除這個index.php?
步驟
1 apache環境下:
通過 .htaccess 文件來設置一些簡單的規則刪除它。下面是一個例子,使用「negative」方法將非指定內容進行重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
2 如果項目不在根目錄請把上面這一句改為:RewriteRule ^(.*)$ index.php/$1 [L]
在上面的例子中,可以實現任何非 index.php、images 和 robots.txt 的 HTTP 請求都被指向 index.php。
Nginx環境下:
修改nginx配置文件,在SERVER段中添加如下代碼:
location /{
if (-f $request_filename) {
expires max;
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
㈧ windows下 php+CI+apache 怎麼刪除URL路徑中的index.php
默認情況下,index/index.php/news/article/my_article 你可以很容易的通過 .htaccess 文件來設置一些簡單的規則刪除它。下面是一個例子,使用「negative」方法將非指定內容進行重定向: RewriteEngine on RewriteCond $1 !^(index\.phpimagesrobots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] 注意:如果你的項目不在根目錄請把上面這一句改為:RewriteRule ^(.*)$ index.php/$1 [L] 在上面的例子中,可以實現任何非 index.php、images 和 robots.txt 的 HTTP 請求都被指向 index.php。 我的終極解決方案 但在實踐中,以上方案僅適用於與運行於Apache環境下的伺服器且並不具有充分的普遍適用性!當CI程序位於非根目錄或位於某些虛擬主機上時,以上解決方案會引起」404錯誤」或」no input file specified」等錯誤.網路參考過相關問題的解放方案後,找到了一種具有通用性的有效刪除URL路徑中index.php的方法,代碼參考如下: index位於根目錄時,你可以在index.php所在的根目錄里新建.htaccess文件並使用以下代碼: RewriteEngine on RewriteCond $1 !^(index\.phprobots\.txt) RewriteRule ^(.*)$ /index.php?/$1 [L] 當index.php不在根目錄時,你可以在index.php所在目錄里新建.htaccess文件並使用以下代碼: RewriteEngine on RewriteCond $1 !^(index\.phpimagesrobots\.txtl) RewriteRule ^(.*)$ /path_to_app/index.php?/$1 [L] 注意把path_to_app換成你的index.php所在文件的目錄.假設你的index.php放在根目錄的tool子文件夾下,你可以這樣寫: RewriteEngine on RewriteCond $1 !^(index\.phpimagesrobots\.txtl) RewriteRule ^(.*)$ /tool/index.php?/$1 [L] 以上方案應該可以解決Apache環境下如何有效刪除URL中index.php的問題,
㈨ ci框架怎麼隱藏index.php和控制器
在根目錄里添加一個名為.htaccess的文件,內容為:
<IfMolemod_rewrite.c>
RewriteEngineon
Options+FollowSymLinks
RewriteBase/
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^(.*)$index.php/$1
</IfMole>
<IfMole!mod_rewrite.c>
ErrorDocument404/index.php
</IfMole>
allowfromall
然後修改你的ci框架中 application/config文件夾中的 routes.php:
$route['default_controller']="你的控制器名字/方法";
$route['404_override']='';
㈩ index.php是什麼
index是普遍意義上的「首頁」,也就是你輸入一個域名後會打開一個頁面,基本上就是index.xxxx(基本上首頁都不會把index.xxxx顯示在url里,但也不絕對)
後面的php是「Hypertext Preprocessor」,一個腳本語言,與asp、jsp一樣是用來處理網站各種事物的程序。
(10)ciurlindexphp擴展閱讀:
index.php的函數語法介紹:
1、語法:INDEX(array,row_num,column_num)返回數組中指定的單元格或單元格數組的數值。
INDEX(reference,row_num,column_num,area_num)返回引用中指定單元格或單元格區域的引用。
2、參數:Array為單元格區域或數組常數;Row_num為數組中某行的行序號,函數從該行返回數值。
如果省略row_num,則必須有column_num;Column_num是數組中某列的列序號,函數從該列返回數值。如果省略column_num,則必須有row_num。
Reference是對一個或多個單元格區域的引用,如果為引用輸入一個不連續的選定區域,必須用括弧括起來。
Area_num是選擇引用中的一個區域,並返回該區域中row_num和column_num的交叉區域。選中或輸入的第一個區域序號為1,第二個為2,以此類推。如果省略area_num,則INDEX函數使用區域1。