當前位置:首頁 » 編程語言 » 去掉ci的indexphp

去掉ci的indexphp

發布時間: 2022-12-26 20:12:56

❶ 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的問題,

❷ 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文件。 文件代碼如下: RewriteEngine On RewriteCond %{REQUEST

❹ phpCI框架 如何去掉默認index.php

下面是去掉index.php的操作
PHP CodeIgniter(CI)去掉 index.php - Langjun - 博客園
設置訪問的默認路徑是在
文件下,找到
$route['default_controller'] = "index"; 默認的為welcome 改為你的訪問index.php之後的參數
我的訪問首頁

遇到類似的問題,你可以去後盾人平台看看的哦,裡面的東西不錯應該能幫你解決一些不明白的問題(❁´◡`❁)*

❺ 在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;
}
}

❻ CI框架去掉index.php問題後,還是提示was not found on this server

CI的index。php是入口文件,你刪除了 當然干什麼都不行了

RewriteRule ^(.*)$ /ci_news/index.php/$1 [L]

熱點內容
電腦配置點評怎麼選 發布:2025-07-05 02:39:23 瀏覽:1000
如何配置與鋅反應的稀硫酸 發布:2025-07-05 02:39:20 瀏覽:935
php分割文件 發布:2025-07-05 02:22:15 瀏覽:478
sql平均成績語句 發布:2025-07-05 02:11:41 瀏覽:277
java離線 發布:2025-07-05 02:11:35 瀏覽:66
php變數賦值給變數 發布:2025-07-05 02:10:56 瀏覽:558
javaequals方法 發布:2025-07-05 01:57:23 瀏覽:98
sqlsever外鍵 發布:2025-07-05 01:41:04 瀏覽:738
鳳凰衛士加密軟體 發布:2025-07-05 01:39:36 瀏覽:636
桌面軟體編程 發布:2025-07-05 01:32:17 瀏覽:993