❤️ AZDIGI has officially updated to a new blog system. However, some posts may have incorrect or mismatched images. Please click the Report article button at the bottom of the post so AZDIGI can update as quickly as possible. Thank you!

Usually, you use www.domain, but in some cases, if you have not set up or pointed the domain IP, it will not take effect. In this article, AZDIGI will guide you to use www and no www with a .htaccess file

1. Use www for domain

To use www.domain, you must point www to the hosting IP with an A record; by default, www is also a sub. You open the .htaccess file and add the following code

Note: Replace mydomain with your domain

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

2. On the contrary, if you don’t want www

For a shorter URL for easy brand recognition and think about removing www.domain.

You open the .htaccess file and add the following code

Note: Replace mydomain with your domain

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

Additional information: In both cases, the 301 parameter is very important, it means permanent redirect, so do not leave this parameter out.

Share:
This article has been reviewed by AZDIGI Team

About the author

Thạch Phạm

Thạch Phạm

Đồng sáng lập và Giám đốc điều hành của AZDIGI. Có hơn 15 năm kinh nghiệm trong phổ biến kiến thức liên quan đến WordPress tại thachpham.com, phát triển website và phát triển hệ thống.

10+ years serving 80,000+ customers

Start your web project with AZDIGI