I am about to switch my blog onto a subdomain blog.example.com so I can have two different WordPress themes installed. Currently, my blog resides at example.com/blog and I was wondering if there were any special 301 redirects or issues that may arise? Would the below 301 redirect format work?

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^blog/$ http://blog.example.com/? [L,R=301]

or should it be

Redirect 301 /blog http://blog.example.com/
  • Either of those should work. Oct 18, 2016 at 18:21
  • 1
    You should match training slashes on Redirect arguments. Your two solutions are subtly different. The first only redirects the exact URI path /blog/ when in the directory context. The second redirects any URI path starting /blog, so /blog/some/thing/else would be redirected to blog.example.com/some/thing/else
    – Unbeliever
    Oct 18, 2016 at 19:14
  • Is this intended to go in your server config or per-directory .htaccess file? @StephenOstermiller Since this is WordPress, only the first (mod_rewrite) type of redirect should be used in order to avoid any potential conflict.
    – MrWhite
    Oct 18, 2016 at 19:14
  • Just out of curiosity why can't you have two themes installed on /blog? I don't see the point of the redirect for the reason you stated. For SEO yes, I redirect blog.example to example/blog Oct 18, 2016 at 19:53
  • @ErikThiart Hi Erik, it's a long story! You see our company was setup on linux hosting than a few years back we got a blog and that was setup as wordpress, however the main site was still .php (the hosting provider said it has been setup as a multi-site, however it was not using that capablility?). Than we switched our main site to wplast year - and now last month switched our hosting to wp hosting package, which significantly sped up the site. However our package does not allow a multi-site therefore it was suggested to make the blog on subdomain so that we'd have two seperate wp installs.
    – jenna
    Oct 19, 2016 at 12:54

1 Answer 1


Since you mention WordPress then only the first (mod_rewrite) solution will work reliably. WordPress uses mod_rewrite for internal routing, so you should also use mod_rewrite for external redirects. Redirect is a mod_alias directive and executes later in the request, so you could end up with a confusing redirect.

However, the redirect posted only redirects the home page of the blog. Presumably you also want to redirect all the internal pages as well? In which case you will need something like the following in .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [L,R=301]

However, it might also depend on where the main domain and subdomain are pointing. Do they point to the same place on the file system? A subdirectory? Somewhere entirely different?

  • 1
    Thank you for your answer it has been very helpful I did not know one line of code could redirect all /blog pages so I had made a file with a redirect for each individual page/post/etc.! The subdomain and domain will be pointing to the same place so I will use the above code thanks again!
    – jenna
    Oct 19, 2016 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.