If you’re trying to deal with URLs on your website redirecting to the incorrect variations, you may have to redirect the non-WWW version of your website to the WWW version of your site (if that’s the primary URL of your site) or vice versa. Luckily, besides all the cool behind-the-scenes improvements in Rank Math, it also makes it extremely easy to fix the dreaded “redirection of non-www to www version” in less than a few minutes…
In this knowledgebase article, we’ll walk you through how to redirect the non-www version to the www version of your website.
How to Redirect Non-WWW Version to WWW Version
To redirect non-www to www version, you’ll need to enter a piece of code in the .htaccess file.
1 Edit .htaccess File
Rank Math lets you edit your website’s .htaccess file inside the WordPress dashboard. To edit the file, navigate to the WordPress Dashboard > Rank Math > General Settings > Edit .htacess as shown below:
2 Add the Redirection Rule
To add a redirection rule to your .htaccess file, click the check box below the warning and add the code snippet after #END WordPress
.
Add the following code snippet and click on Save Changes.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
You can use the htaccess tester tool to debug and ensure that the rewrites are correct before adding them to the .htaccess file.
How to Redirect Non-www URLs to www on NGINX Servers
If you are using an NGINX server, you can redirect all non-www URLs to the www version by adding the following configuration to your NGINX server block:
server {
listen 80;
server_name yourdomain.com;
return 301 $scheme://www.yourdomain.com$request_uri;
}
Replace yourdomain.com
with your actual domain name. This configuration will ensure that any request to yourdomain.com
is permanently redirected to www.yourdomain.com
.
After updating the configuration, reload NGINX for the changes to take effect:
sudo nginx -s reload
And that’s it! You have successfully enabled a .htaccess rule that will redirect all visitors from a non-www version to the www version of your website! If you still have any questions about how to redirect the non-www version to the www version of your website – you’re always more than welcome to contact our dedicated support team. They are available 24/7, 365 days a year…