问题原文
原帖链接 · jenna · CC BY-SA 3.0
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/
已采纳解答
原帖链接 · MrWhite · CC BY-SA 3.0
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?
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
