Thanks for reading. I have done a search, read multiple posts (lost count) and still having trouble with something that seems simple.
I am trying to redirect or rewrite from:
http://www.mysite.com/blog/
to
http://www.blog.mysite.com/
Firstly, should this go in the htaccess file in the root directory or in the blog subdirectory?
Secondly, a few of my attempts are below:
(Attempt 1)
RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^blog\/?$ "http\:\/\/www\.blog\.mysite\.com\/" [R=301,L]
(Attempt 2)
RewriteCond %{HTTP_HOST} ^(www\.)?blog\.mysite\.com$
RewriteCond %{REQUEST_URI} mysite.com/blog
RewriteRule ^(.*)$ /blog/$1 [L]
(Attempt 3)
RewriteRule http://mysite.com/blog http://www.blog.mysite.com/$1 [R=301,L]
(Attempt 4)
rewriterule ^blog/(.*)$ http://www.blog.mysite.com/$1 [r=301,nc]
Any help is greatly appreciated.
Your first attempt looks nearly correct. I’m going to remove the
ORcondition and pack both those into a single regex, and remove all the escaped slashes and quotes from the rewrite target:This should be placed in the root directory’s .htaccess.