Adding the www prefix to domain URLs
You can automatically add the www prefix to your domain’s URLs by using Apache rewrite rules in a custom .htaccess file. To do this, follow these steps:-
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.
📘 Note For more information about how to use .htaccess files, please see this article.
- Copy and paste the following lines of text into the .htaccess file:
- Save the .htaccess file.
- 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.
Removing the www prefix from domain URLs
You can automatically remove the www prefix from your domain’s URLs by using Apache rewrite rules in a custom .htaccess file. To do this, follow these steps:-
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.
📘 Note For more information about how to use .htaccess files, please see this article.
- Copy and paste the following lines of text into the .htaccess file:
- Replace example.com in the final line of text with your own domain name.
- Save the .htaccess file.
- 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.