Redirecting www to non-www using .htaccess file


Can someone please help me with a coding problem I’m having redirecting www to non-www.

I’ve used Cloudflare’s free service for a padlock secured connection on my selling website ( which uses Rapidcart Pro.

Non www URL works fine however is not secure and needs to be redirected to I have created an .htaccess file (using suggested code from;

RewriteCond %{HTTP_HOST} ^www\.foragers\.scot [NC]
RewriteRule ^(.*)$$1 [L,R=301]

But this is taking me to with a 404 Not Found error.

The .htaccess file is located in the root directory and I have tried moving it to the public_html folder but this is not the solution.

I hope some kind person can see where I am going wrong.

Many thanks,

Not sure if I under stand what you’re saying.
But this should redirect sites from WWW to non-WWW (secured):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

Many thanks Doug,
I’ve edited the .htaccess files as per your instruction;

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.foragers\.scot$
RewriteRule ^/?$ "http\:\/\/foragers\.scot\/" [R=301,L]

But still takes me to I need it to go to (without public_html/). See attached screen grabs.

All my website files reside in the public_html folder.

I think the .htaccess file needs a minor edit to correct this but as you will gather my coding skills are pretty basic so any suggetions would be most appreciated.

Best regards,

That’s not at all the code I gave you above.

The code I listed above has no URL’s as they aren’t needed, it also has different options to support the Query string.

If I paste this into my browser:


I get this:

You have something else going on. RapidCart Pro is adding a query string to the end of the URL. That should work fine with the code I gave you but you’re not using the code above(it has been tested and works with query strings). I’m not seeing any redirects happening at all. No public_html like you show. No stripping of the www like what you wanted.

It could be that because you used 301 (permeant) with the old htaccess file they may very well be being cached. 301’s have no expiry date (why they are called permeant) so the can technically be cached forever.

The code you posted I just tested and doesn’t work to strip the www.

Might I suggest you double check the file placement and delete the .htaccess file you currently have. Copy and paste exactly what I have given you and try again. You might want to change the r=301 to r=302 until you are sure it works 100% of the time for every URL on the site. The change it back to the r=301.

Sorry I assumed I had to paste in my specific URL. After pasting in the correct code and clearing site data it works perfectly.
really appreciate your help.
Many thanks,