I would like to redirect
www.example.com
toexample.com
. The following htaccess code makes this happen:RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
But, is there a way to do this in a generic fashion without hardcoding the domain name?
Answer
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Same as Michael’s except this one works 😛
Attribution
Source : Link , Question Author : deepwell , Answer Author : Volomike