0

I have an issue with my www not redirecting to non-www after setting up SSL and I can't figure it out, there are so many rules already set so IDK what is messing me up.

Any help would be greatly appreciated!

Here is the current section of .htaccess configuration that I believe is giving issues:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on [OR]
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [E=WPR_SSL:-https]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [E=WPR_ENC:_gzip]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_|wp-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_) [NC]
RewriteCond %{HTTP_USER_AGENT} !^(facebookexternalhit).* [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}.html%{ENV:WPR_ENC}" -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* "/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}.html%{ENV:WPR_ENC}" [L]
</IfModule>



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
</IfModule>
  • Possible duplicate of [apache redirect http to https and www to non www](https://stackoverflow.com/questions/9945655/apache-redirect-http-to-https-and-www-to-non-www) – Amadeu Antunes Dec 12 '17 at 23:15

2 Answers2

0

I'm not an expert in this by any means, but I don't see where you're attempting the redirect. This has always worked for me:

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

I've always put at the top of my .htaccess, but I'm speaking from limited experiences - again not an expert here.

Hope this helps!

EDIT: While I think this should work for you, I'm not sure if it's best practice. I'd reccomend waiting for someone else, more knowledgeable, to answer before making changes to your site. I'll be following this question looking for other answers as well.

TCooper
  • 1,545
  • 1
  • 11
  • 19
0

Also what are your WordPress Address and Site Address set to in Settings -> General ? If you use your preferred non-www version there, that should take care of it in my experience.

Jo Batkin
  • 108
  • 9