Fixing non-www Redirection

In this Article

Redirection non-www → www

If you have a problem with the redirection of the non-www to the www version of your URL, use the following helper plugin. The plugin will add the correct redirect rule 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 non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]