การทำ 301 Redirect สำหรับเปลี่ยน http เป็น https

การติดตั้ง ssl certificate บนเว็บไซต์ของคุณจะทำให้ Link การเข้าถึงเว็บไซต์ของคุณเปลี่ยนไปจาก http เป็น https ทำให้ Search Engine หา Link เดิมไม่เจอซึ่งอาจเกิดผลเสียทำให้ผู้ชมเว็บไซต์ลดลงได้ วิธีแก้ไขสามารถทำได้โดยทำ 301 Redirect ครับแต่เป็น 301 Redirect แบบพิเศษสำหรับ https โดยเฉาพะ วิธีนี้เป็นวิธีที่จะบอก Search Engine และผู้ใช้ทั่วไปว่าเว็บไซต์ของเรา ตอนนี้เปลี่ยนจาก http เป็น https แล้ว รวมไปถึง Redirect ผู้ชมจาก http มาเป็น https ทั้งหมดด้วยครับ

 

1. สร้างไฟล์ .htaccess
2. เพิ่ม Code ด้านล่างนี้เข้าไปครับ

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 

เสร็จเรียบร้อยแล้วลองทดสอบเข้าเว็บไซต์ของคุณด้วย http หากตั้งค่าถูกต้องคุณจะถูก redirect ไปยัง https ทันทีครับ

 

บทความจาก Force https using an .htaccess file

https://help.directadmin.com/item.php?id=624

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

วิธีเขียนโค้ด php ใน ไฟล์นามสกุล html

อยากเขียนโค้ด php ใน ไฟล์นามสกุล html ทำได้โดย .htaccess ความรู้เก่า   <IfModule...

การทำ Redirect from HTTPS เป็น HTTP

There are some specific cases when you want to redirect particular URL or a single website to be...

การทำ Redirect from HTTPS เป็น HTTP

There are some specific cases when you want to redirect particular URL or a single website to be...

จะทำการ block IP โดยใช้ .htaccess ได้อย่างไร

สามารถทำได้โดยระบุ IP ที่ต้องการบลอกที่ .htaccess ไฟล์ โดเยการสร้างไฟล์วางไว้ที่ public_html...

วิธีการเปลี่ยนหน้าแรกจากไฟล์ index เป็นชื่ออื่นที่ต้องการใน hosting ของเรา

ภายในไฟล์ .htacess ให้ระบุข้อมูลต่อไปนี้ครับ DirectoryIndex ชื่อไฟล1 ชื่อไฟล์2 ชื่อไฟล์3...