075-845-490 | 097-165-2449
Line ID: @hostnakhonitech
🎉 โปรโมชั่นพิเศษ! ลด 10% สำหรับลูกค้าใหม่
NakhoniTech
075-845-490
support@NakhoniTech.com

การเขียน mod rewrite เปลี่ยนเส้นทาง domain.com ไปที่ www.domain.com (no-www to www) Print

  • 1

ถ้าคุณต้องการบังคับให้ลูกค้าใช้ www.domain.com คุณสามารถเปลี่ยนเส้นทางจาก domain.com ไปเป็นเวอร์ชัน www โดยใช้ไฟล์. htaccess

ในโฟลเดอร์ public_html ของคุณให้สร้างไฟล์ที่ชื่อว่า

.htaccess

และเพิ่มcode

#non-www

# Will automatically redirect requests to www to non-www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


# Require WWW
# Will automatically redirect requests to non-www to www
# This will exempt robots.txt for search engines
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteCond %{REQUEST_URI} !^/sitemap\.(xml|xml\.gz)$
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]
</IfModule>

 

บทความจาก  Redirect domain.com to www.domain.com

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

 


Was this answer helpful?

« Back