Wildcard redirect all www to non-www urls for Magento instances running on cPanel Litespeed Server

Today I faced an issue with the standard cPanel redirects not working with Magento running on litespeed.

When you create a redirect from within cPanel, a Mod Rewrite rule is written to the .htaccess file located in the document root of the domain the rule is for.

If you open the .htaccess file, you should see this at the very bottom (after creating the redirect in cPanel):


RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*)$ "http\:\/\/domain\.com\/$1" [R=301,L]

There are two issues related to litespeed.

1. The Rewrite rule must be placed at the top of your .htaccess file (some rules set by Magento conflict with litespeed’s rule interpreter)
2. The Rewrite rule must be formatted correctly (remove the escaping backslashes from the RewriteRule).

Your update rule should look like this:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*)$ "http://domain.com/$1" [R=301,L]

After making these changes and saving your .htaccess file, your Magento www URLs should now redirect to their respective non-www URL counterparts.

Leave a Reply