如何使用 URL 内容进行域重定向?

How to domain redirect with URL content?

我最近将我的博客移到了单独的域,所以我试图在我以前的站点中定义 URL 重定向到我的博客。

我想做的是http://sub.exmple.com/blog/{any page} should redirect to http://www.new-blogdomain.com/{旧页url}

我正在尝试的代码是:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.exmple.com [NC]
RewriteRule ^(.*)$ http://www.new-blogdomain.com/ [R=301,L]

如果我转到 sub.exmple.com/{any page} 并转到 http://www.new-blogdomain.com/{old page} but this RULE should apply if my old URL contain blog keyword http://sub.exmple.com/blog/,以上代码有效。

试试下面的规则,

RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.new-blogdomain.com/ [R=301,L]

尝试:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.exmple\.com [NC]
RewriteRule ^\/?blog\/(.*)$ http://www.new-blogdomain.com/ [R=301,L]

而不是 ^\/?blog\/(.*)$,您可以尝试 ^blog\/(.*)$^\/blog\/(.*)$,具体取决于服务器配置