After adding an SSL certificate I want to 301-redirect all my site's URL variations to non-www ones. I tried creating a redirect from cPanel for all other variations.
Every other URL variations redirect except for https://www.example.com
, this one does not redirect to https://example.com
. Both URLs can be accessed and won't redirect to the non-www ones.
I've added canonical, Google has crawled and indexed both. Analytics gave a redundant hostname notification. I also tried redirecting from an htaccess file using these code:
# BEGIN SSL
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ https://example.com$1 [R,L]
# END SSL
and
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Both failed.
All I want is to redirect all URL variations, secure or non-secure, to https://example.com
(non-www secure version).
.htaccess
files enabled with anAllowOverride
directive in your server or virtual host config?R
redirect flag is302
. In your case, be sure to stateR=301
for each redirection, for your canonical URL to enforce quickly.