From Ginger:
Hiya, I enjoy your blog and humor within
In case you still do posts from the “mail bag” — I have seen mention of .htaccess on your site and I’m curious how it relates to the subject of redirects. For example, in my day job we have a site that has two ways to access an external support site.
So, we want to redirect: www.example.com/support and support.example.com to the same external support site. In the past, I would go to our host and edit the DNS to redirect on these URLS to the external site. Is that the best way or should I be handling this in the .htaccess file now that we’re on WordPress?
Depends on how lazy I am.
DNS is great because I can just send support.example.com over, but this only works if the external site lets me do that. I can point my domain at tumblr.com all I want, yet until I add my custom domain to their settings, the URL won’t work. This is why your domain mappings in Multisite don’t always work, folks. You have to tell WordPress, the name servers, and the server that the domain lives there. If you can? Super simple for the subdomain, but not for the subfolder.
Which brings us to .htaccess:
Apache 2.2
RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^support(.*)$ http://supporturl.com/ [L,R=301] RewriteCond %{HTTP_HOST} ^support\.example\.com [NC] RewriteRule ^(.*) http://supporturl.com/ [L,R=301]
Apache 2.4
<If "%{HTTP_HOST} == 'example.com' "> RedirectMatch ^support(.*) http://supporturl.com/ </If> <If "%{HTTP_HOST} == 'support.example.com'"> RedirectMatch (.*) http://supporturl.com/ </If>
Now someone will note that specifying the HTTP_HOST for example.com is silly, but I disagree. This lets me use http://foo.example.com/support/
to redirect somewhere else. I don’t worry about the www part because I always force no-www on all my domains. Saves me steps later.
Oh and I’m glad Ginger likes my humor. I don’t know how to turn it off!
Comments
2 responses to “Mailbag: .htaccess Magic with Subdomains and Subfolders”
Awesome! Thanks so much for answering my query π
why would you want to turn your humour off on your Blog, that would be a crime π