In this article we will show you how to add or remove www url prefix in your website. For Search Engine Optimization (SEO) purposes, it is preferable to have a website respond only to https://www.example.com or https://example.com, not both. Otherwise, search engines see duplicate content on the www and non-www domains, and may downgrade the site ranking.
Removing the www prefix from domain URLs
1. Create an .htaccess file in your public_html directory. If you already have an .htaccess file in the public_html directory, you can modify it. 2. Copy and paste the following lines of text into the .htaccess file
# Remove www from any URLs that have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
3. Replace example.com in the final line of text with your own domain name. 4. Save the .htaccess file. 5. To test the configuration, use your web browser to visit http://www.example.com, where example.com represents your domain name. The browser should be redirected to http://example.com.
Adding the www prefix to domain URLs
1. Create an .htaccess file in your public_html directory. If you already have an .htaccess file in the public_html directory, you can modify it. 2. Copy and paste the following lines of text into the .htaccess file
# Add www to any URLs that do not have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
3. Save the .htaccess file. 4. To test the configuration, use your web browser to visit http://example.com, where example.com represents your domain name. The browser should be redirected to http://www.example.com.