Forum Moderators: phranque
The following example routes all mydomain.com traffic to www.mydomain.com
########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule (.*) http%2://www.mydomain.com/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF
How do I do the reverse and route all www.mydomain.com traffic to mydomain.com?
Also how would I modify either to incorporate a sub domain?
Thanks in advance, DM.
########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.subdomain\.mydomain\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.subdomain\.mydomain\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule (.*) http%2://www.subdomain.mydomain.com/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF
########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule ^(.*)$ http%2://example.com/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF
Jim
########## Begin - Rewrite rules to enhance SEO SEF
#
RewriteCond %{HTTP_HOST} ^www\.subdomain\.example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com\. [NC,OR]
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com:[0-9] [NC]
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule ^(.*)$ http%2://subdomain.example.com/$1 [R=301,L]
#
########## End - Rewrite rules to enhance SEO SEF
For SEO purposes I know its generally better to use one or the other but would you recommend to redirect to www.example.com or the canonical "example.com"