Hi there,
Thank you for getting back to us. We’re glad to hear that you were able to edit your .htaccess file via SFTP. However, we’re sorry that you’re still facing the issue of www and non-www versions of your URL not being redirected to the same site.
The code that you added to your .htaccess file is only for forcing HTTPS on your site, which means that it will redirect any HTTP requests to HTTPS. However, this code does not affect the www and non-www versions of your domain. You need to add another code snippet to your .htaccess file to redirect one version to the other.
There are different ways to do this, depending on which version you want to use as your canonical one (i.e. main URL). For example, if you want to use the non-www version as your canonical one, you can add this code after the HTTPS redirection code:
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
This code will redirect any requests from www.yourdomain.com
to yourdomain.com
. Don’t forget to replace yourdomain.com with your actual domain name.
Alternatively, if you want to use the www version as your canonical one, you can add this code instead:
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
This code will redirect any requests from yourdomain.com
to www.yourdomain.com
.
You can find more examples and explanations of how to redirect www and non-www URLs here: Choosing between www and non-www URLs and How to Redirect WWW Version to Non-WWW Version of Your Website.
We hope this helps you solve the issue and make your site consistent. If you have any other questions or concerns, please let us know. We’re always here to help you.
Thank you for using Rank Math!