PHP架構CodeIgniter--URL去除index.php

來源:互聯網
上載者:User

標籤:記錄   參數   welcome   開啟   function   請求   重新導向   檔案   tac   

今天學習CodeIgniter簡稱CI的第一天,記錄下學習心得。

CI中國https://codeigniter.org.cn/user_guide/general/urls.html?highlight=url 這裡有介紹

example.com/class/function/ID
  1. 第一段表示要調用的控制器 類 ;
  2. 第二段表示要調用的類中的 函數 或 方法 ;
  3. 第三段以及後面的段代表傳給控制器的參數,如 ID 或其他任何變數;
移除 URL 中的 index.php

預設情況,你的 URL 中會包含 index.php 檔案:

example.com/class/function/ID

1、

如果你的 Apache 伺服器啟用了 mod_rewrite ,你可以簡單的通過一個 .htaccess 檔案(放在index.php同級目錄)

再加上一些簡單的規則就可以移除 index.php 了。下面是這個檔案的一個例子, 其中使用了 "否定條件" 來排除某些不需要重新導向的項目:

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]

在上面的例子中,除已存在的目錄和檔案,其他的 HTTP 要求都會經過你的 index.php 檔案。

2、

 httpd.conf 開啟 LoadModule rewrite_module modules/mod_rewrite.so 如果已開啟,可以忽略。3、重啟apache 4、application/config.php 中的$config[‘index_page‘] = ‘index.php‘;  --》index.php$config[‘index_page‘] = ‘‘; http://192.168.1.89/welcome/index

 

PHP架構CodeIgniter--URL去除index.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.