Http to https and www to non www almost working

Website: mesolithico.freecluster.eu

(No error message)

In order to avoid duplicate content as warned about by Google search console, I have managed to redirect all http requests to https using the .htaccess-code from the helpcenter. For the same reason I need to redirect all www-requests to non-www-requests too. I added a rule to the .htaccess-file, this rule only works for the main-page www.mesolithico.freecluster.eu but not for all other pages even not for www.mesolithico.freecluster.eu/index.php (or any other subpage). I guess I need to add a wildcard behind the rewriteCond, but I don´t know exactly which one (I tried many and they don´t work)

This is my .htaccess now:
RewriteEngine On

original code provided by infinityfree helpcenter

RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

this rewrite only works on the main site indexpage:

RewriteCond %{HTTP_HOST} www.mesolithico.freecluster.eu
RewriteRule ^/?$ https://mesolithico.freecluster.eu [R=301,L]

Anybody knows how I can make every www-request for every page redirected to non-www?

Thanks!

Replace everything in your .htaccess file with this, then clear your cache.

##Force HTTPS##
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

##Clear www preface###
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
3 Likes

This works… thanks!!!

2 Likes

Not a problem, glad I could help!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.