Forum Moderators: phranque
# Code for use only in server config file, outside any <Directory> containers (will not work in .htaccess or inside a <Directory> container):
#
# If non-www hostname is requested
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
# or if www.example.com hostname is requested with appended FQDN token and/or port number
RewriteCond %{HTTP_HOST} ^www\.example\.com(\.|\.?:[0-9]+)$ [NC,OR]
# or if any hostname other than www.example.com is requested with no additional URL-path
Rewritecond %{HTTP_HOST}/$1 !^www\.example\.com/.+$
# then externally redirect to www.example.com, retaining the originally-requested URL-path
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
RewriteEngine On
Rewritecond %{HTTP_HOST}/$1 ^static\.example\.com [NC,OR]
Rewritecond %{HTTP_HOST}/$1 ^origin.\stat\.example\.com [NC,OR]
Rewritecond %{HTTP_HOST}/$1 ^stat\.example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]