Codeigniter 4 จะมี folder public โผล่มา เพื่อให้เราใช้งานในเวอร์ชั่น development ( เวอร์ชั่นที่อยู่ในขั้นตอนการพัฒนา ยังไม่ได้เปิดใช้งานจริง ) และเมื่อนำโปรเจคไปใช้งานจริง เราอาจจะไม่ต้องการให้ชื่อโฟลเด้อ public แสดงบน url
วิธี ลบโฟลเด้อ public ออกจาก url สามารถทำได้ง่าย ๆ ใน 3 ขั้นตอน ง่ายๆ ดังนี้
- ในโฟลเด้อ public ให้ย้าย ไฟล์ index.php, .htaccess และ robot.txt ออกมาไว้ที่ root ของโปรเจค จากนั้นลบ folder public ทิ้งได้เลย
- เปิดไฟล์ index.php จากนั้นให้แก้ไขตัวแปร FCPATH ให้พาธถูกต้อง
จากเดิม (บรรทัดที่ 34)require FCPATH . '../app/Config/Paths.php';
แก้ไขเป็นrequire FCPATH . 'app/Config/Paths.php' - เปิดไฟล์ spark จากนั้นให้แก้ไขตัวแปร pathsPath ให้พาธถูกต้อง (หากเราไม่ทำการเปลี่ยนเราจะใช้ spark ไม่ได้เลย)
จากเดิม (บรรทัดที่ 69)define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR .'public'.DIRCTORY_SEPARATOR);// Load our paths config file// This is the line that might need to be changed, depending on your folder structure.require FCPATH . '../app/Config/Paths.php';// ^^^ Change this line if you move your application folder
แก้ไขเป็นdefine('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);// Load our paths config file// This is the line that might need to be changed, depending on your folder structure.require FCPATH . 'app/Config/Paths.php';// ^^^ Change this line if you move your application folder
ความคิดเห็น
แสดงความคิดเห็น