views:

23

answers:

2

I've tried a bunch of examples here on SO and modifed them, but none are exactly what I need and as a result either fail with 500 server errors (meaning the rewrite rules are wrong) or redirect just the subdomain to the domain and not any of the full URLs of pages.

I need to redirect all URLs under blog.mydomain.com to www.mydomain.com/blog, i.e. redirect blog.mydomain.com/page1 to www.mydomain.com/blog/page1

This

RedirectMatch 301 ^/ http://mydomain.com/blog/

redirects all URLs of blog.mydomain.com to the root of mydomain.com/blog/, not the full URL. Any ideas?

A: 

I use this to redirect one domain to another, but should work fine for subdomains/subdirectories:

RewriteCond %{HTTP_HOST} ^blog\.mysite\.com$ [NC]
RewriteRule ^ http://mysite.com/blog%{REQUEST_URI} [R=301,L]
Kevin
That 404's with a url like blog.mydomain.com/myurl
songdogtech
How is your subdomain set up? Are you using cPanel?
Kevin
+1  A: 
RedirectMatch permanent (.*) http://mydomain.com/blog/$1
toscho
Works perfectly, thanks. I was missing the URL matching bits of code.
songdogtech