Fixing non-www redirection

Not having the correct redirects in place for the various versions of your domain can cause problems. There are a few ways to set up these redirects.

⚠️  After implementing any of the following solutions remove old configuration and cache files by following this guide .

In this Article

Ask your host

Redirects done at the server level will be faster than those done in the htaccess file. The best solution is to your ask your host to set it up for you in the server configuration. 

Cloudflare Page Rules

If you use Cloudflare and are comfortable with their Page Rules feature you can use them for redirects (our Support team cannot help you with this).

Redirection non-www → www

The following helper plugin will add the correct redirect rule from the non-www to the www version of your URL, to your .htaccess file.

📥  Download (.zip): WP Rocket | Redirect non-www to www
Developers: You can find the code for this plugin on GitHub.

Manual code edit required before use!
You will have to manually edit 2 lines of code:
Replace example\.com with your domain. Keep the backslash \!
Replace http://www.example.com with your WordPress site URL. Apply the protocol that is correct for your site: http:// or https://

These are the rules that the above helper plugin adds to the .htaccess file:

# Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Redirection www → non-www

If you need the opposite rule (www to non-www), use this plugin:

📥  Download (.zip): WP Rocket | Redirect www to non-www
Developers: You can find the code for this plugin on GitHub.

Manual code edit required before use!
You will have to manually edit 2 lines of code:
Replace www.example\.com with your domain. Keep the backslash \!
Replace http://example.com with your WordPress site URL. Apply the protocol that is correct for your site: http:// or https://

These are the rules that the above helper plugin adds to the .htaccess file:

# Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.