RewriteCond %{HTTP_HOST} !^mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]
This strips www from the URL.
Without the rule the subdomain works (blog.site.com). With the rule it converts back to (site.com/blog) and shows 404 errors.
What do I need to do to keep this from affecting the subdomain(s)?
Also, I'm curious if removing the www. is a good thing? I've heard it doesn't matter as long as you pick one and stick to it. I'm also using <link rel="canonical" ... /> to re-enforce it.
With
(blog\.)?at the begin blog. becomes optional and so it will redirect only if it is different fromblog.mysite.comandmysite.com.A different way to do the same would be:
Which means if hostname is different then
mysite.comandblog.mysite.comredirect.To avoid duplicity it is good to choose between www or non-www and redirect every thing for that.
So if u use www then redirect non-www to www and vice versa.