การ Config Linux Server เพื่อรองรับการตัด Index.php ของ codeigniter framework
ขั้นตอนที่ 1: สร้างไฟล์ .htaccess แล้วไปว่าง root หรือ ที่ๆระดับเดียวกับไฟล์ Index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
ขั้นตอนที่ 2 : ทำการแก้ไขไฟล์ application>config>config.php ให้เป็นดังตัวอย่างด้านล่าง
$config['base_url'] = '';
$config['index_page'] = '';
ขั้นตอนที่ 3 : แก้ไขค่า Config ของตัว Apache (Webserver)
ใช้คำสั่ง
sudo nano /etc/apache2/apache2.conf
เมื่อเปิดไฟล์เเล้วให้กด Ctrl+W เเล้วพิมพ์ "AllowOverride"
จาก
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
</Directory>
แก้เป็น
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ขั้นตอนที่ 4: เปิด .mod rewrite โดยการใช้คำสั่ง
sudo a2enmod rewrite
ขั้นตอนที่ 5 : ทำการรีสตาร์ท Apache โดยการใช้คำสั่ง ถือเป็นอันเสร็จ
sudo /etc/init.d/apache2 restart
Post a Comment