Http to https and www to non www almost working


(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 but not for all other pages even not for (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}
RewriteRule ^/?$ [R=301,L]

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


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]

This works… thanks!!!


Not a problem, glad I could help!


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