簡體   English   中英

CodeIgniter | 將index.php移到公用文件夾

[英]CodeIgniter | Move index.php to public folder

我是CodeIgniter的新手,可以考慮嘗試一下

  1. 下載了CodeIgniter中可用的代碼
  2. 將基本網址更改為$config['base_url'] = 'http://localhost:8000';
  3. 使用命令php -S 0.0.0.0:3000啟動服務器

一切順利。接下來,我嘗試將index.php文件移動到公共文件夾中-那就是事情開始崩潰的時候。

  1. 將index.php移動到新創建的公用文件夾
  2. 使用以下代碼段創建了一個新文件public / .htaccess

     RewriteEngine on RewriteCond $1 !^(index\\.php|assets|images|js|css|uploads|favicon.png) RewriteCond %(REQUEST_FILENAME) !-f RewriteCond %(REQUEST_FILENAME) !-d RewriteRule ^(.*)$ ./index.php/$1 [L] 
  3. 修改后的$system_path = '../system'; $application_folder = '../application' ; public/index.php

  4. 重新啟動服務器后嘗試訪問該頁面時,我得到404 Resource not found

您是否更改了服務器配置中的根文件夾?

如果將index.php移到另一個文件夾,則應該在服務器設置中將路徑更改為index.php。 在配置文件中。

這很簡單

$system_path = __DIR__ . '../system';
$application_folder = __DIR__ . '../application';

並使用正常的codeignitor .htacess文件,一切運行正常。 Symfony在index.php中也做同樣的事情。 當然,您的CSS,圖像,上傳文件夾應位於公用文件夾內。 然后您可以刪除所有index.html文件,

defined('BASEPATH') OR exit('No direct script access allowed');

聲明;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM