.htaccess redirect www to non-www

Table of Contents
.htaccess redirect www to non-www – New update 2024
The Digital Marketer Journal is packed with articles written by professionals from every current digital marketing field. We add new posts daily. Industry trends, product changes, feature announcements, and more can all be found in this blog.
I usually use non-www URLs for simplicity and having shorter URLs. So, I often redirect all requests to www to their non-www versions. This snippet redirects all requests to www.example.com
to example.com
. It’s generic, works with all domains and doesn’t require you to write the domain name.
RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ [R=301,L]
It should be in your .htaccess
file in your web root folder, or in your virtual host configuration file. Note that it works only with Apache.
If you’re not familiar with editing .htaccess
file, and you’re using WordPress, then use the Slim SEO plugin. It has a redirection module which supports redirecting www to non-www and vice-versa.
Relation articles with .htaccess redirect www to non-www in the same categories
Summary
DIGITAL CHANGING your LIFE | Your #1 resource for digital marketing tips, trends, and strategy to help you build a successful online business. Subscribe to our weekly newsletter that delivers the most actionable, tactical, and timely marketing tips you actually need in 7 minutes or less. Get an edge over the competition, for free.
Categories