Forum Moderators: phranque
RewriteEngine on
# check to make sure it's a www
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.(com|net)) [NC]
# if that's the case, redirect to HTTP_HOST only
RewriteRule (.*) http://%1/$1 [R=301,L]
RewriteEngine on
#
# if requested hostname starts with "www"
RewriteCond %{HTTP_HOST} ^www\.([^.:]+\.(com|net))\.?(:[0-9]+)?$ [NC]
# redirect to hostname without "www."
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteEngine on
#
# if requested hostname starts with "www."
RewriteCond %{SERVER_PORT}s->%{HTTP_HOST} ^(443(s)|[0-9]+s)->www\.([^.:]+\.(com|net))\.?(:[0-9]+)?$ [NC]
# redirect to hostname without "www.", preserving requested HTTP/HTTPS protocol
RewriteRule ^(.*)$ http%2://%3/$1 [R=301,L]
RewriteEngine on
#
# if requested hostname contains "www."
RewriteCond %{SERVER_PORT}s->%{HTTP_HOST} ^(443(s)|[0-9]+)->([^.:]+\.)*www\.(([^.:]+\.)+(com|net))\.?(:[0-9]+)?$ [NC]
# redirect to hostname without "www.", preserving requested HTTP/HTTPS protocol
RewriteRule ^(.*)$ http%2://%3%4/$1 [R=301,L]