首頁 >後端開發 >php教程 >如何從 CodeIgniter URL 中刪除「index.php」?

如何從 CodeIgniter URL 中刪除「index.php」?

Patricia Arquette
Patricia Arquette原創
2024-11-12 18:50:021103瀏覽

How to Remove

CodeIgniter .htaccess 和URL 重寫問題

導航CodeIgniter 應用程式通常需要從URL 中刪除「index.php」,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”,以允許“index.php”使用者造訪具有更清晰語法的頁面。不過,新用戶在這個過程中可能會遇到困難。

刪除「index.php」的關鍵在於修改應用程式設定檔(application/config.php)並在根目錄下建立.htaccess檔案.

1.應用程式設定:

在application/config.php中,確保以下設定:

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2. .htaccess 檔案:

在根目錄中建立一個 .htaccess文件,代碼如下:

RewriteEngine on
RewriteCond  !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]

3.重寫引擎啟用:

透過以下方式確保重寫引擎已啟用:

  • 使用“a2enmod rewrite”啟動它。
  • 將「AllowOverride None」改為/etc/apache2/sites-enabled/000-default 或 /etc/apache2/apache2.conf 中的「AllowOverride All」。
  • 使用指令「sudo /etc/init.d/apache2 restart」重新啟動伺服器".

附加說明:

如果透過「localhost/ci/about」造訪頁面失敗,請考慮:

  • 使用「localhost/ci/index.php/about」或在application/中建立「about」目錄。

以上是如何從 CodeIgniter URL 中刪除「index.php」?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn