Generic htaccess redirect www to non-www


I would like to redirect to The following htaccess code makes this happen:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$$1 [L,R=301]

But, is there a way to do this in a generic fashion without hardcoding the domain name?

Best Solution

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Same as Michael's except this one works :P

Related Question