如何使用.htaccess 301重定向特定的子域名URL?

Fin*_*nch 6 apache .htaccess mod-rewrite redirect

我需要将子域上的特定URL重定向到不同子域上完全不同的 URL.例如:

http://foo.example.com/this-is-my-page
Run Code Online (Sandbox Code Playgroud)

需要301:

http://bar.example.com/this-is-really-my-page
Run Code Online (Sandbox Code Playgroud)

我试过设置一个简单Redirect 301.htaccess但它似乎不起作用.例如:

Redirect 301 http://foo.example.com/this-is-my-page http://bar.example.com/this-is-really-my-page
Run Code Online (Sandbox Code Playgroud)

Fin*_*nch 2

这就是我最终所做的:

# first re-write all foo.example.com requests to bar.example.com
RewriteCond %{HTTP_HOST} ^foo\.example\.com [NC]
RewriteRule (.*) http://bar.example.com/$1 [L,R=301]

# now re-write each individual URL
RewriteRule ^this-is-mypage /this-is-really-my-page [NC,L,R=301]
Run Code Online (Sandbox Code Playgroud)