Forum Moderators: phranque
[ mod_rewrite ]
(www.)domain.foo/sub/blog/someID# -> sub.domain.foo/blog/someID#
If someone could help with two methods, one that would be subdomain-specific (say if the request were 'sub') and one that would apply site-wide to any subdirectory->subdomain.
jdMorgan, anyone? Thanks!
Site used to be run at:
h*tp://domain.com/d/
with several subdirectories below that, such as:
h*tp://domain.com/d/photo/
h*tp://domain.com/d/blog/
etc...
Subdomain has since been created & is fully operational at (same subdirectories still apply):
h*tp://d.domain.com/
Since the old links are not dead and Google, Yahoo, etc have a record of the links, I'd like to 301 rewrite every request for h*tp://domain.com/d/foo/bar/ OR h*tp://www.domain.com/d/foo/bar/ (regardless of URI request) and have it elegantly slide the d in front of as a subdomain, thus h*tp://d.domain.com/foo/bar/
I'm sure it's been asked many times before, but since this is not a question about /creating/ a subdomain - just one regarding a R=301, I can't seem to solve it (also because I'm doing this as a favor for a friend and since my host has automatic subdomain resolving, I'm finding it hard to test). Thanks for any help you've got for me.
Without the RewriteCond you would end up in a dead loop possibly causing some 500 http errors.
Recommended literarure:
URL Rewriting Guide [httpd.apache.org]
mod_rewrite documentation [httpd.apache.org]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.[b]foo[/b]
RewriteRule ^d/(.*) http://d.domain.foo/$1 [R=301,L]