: Redirecting from www.example.com/blog to blog.example.com 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
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/$ blog.example.com/? [L,R=301]
or should it be
Redirect 301 /blog blog.example.com/
More posts by @Kevin317
1 Comments
Sorted by latest first Latest Oldest Best
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/(.*)$ blog.example.com/ [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?
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.