我有一个运行在某个旧域名上的wordpress博客,现在我正在迁移到一个新的域名。
我正在尝试设置从旧网址到新网址的重定向。 但我希望主页的自定义重定向和页面的通用重定向:例如:
1. https://www.oldsite.com --> 301 --> https://www.newsite.com/page1
2. https://www.oldsite.com/page2 --> 301 --> https://www.newsite.com/page2
3. https://www.oldsite.com/page3 --> 301 --> https://www.newsite.com/page3
任何帮助将不胜感激!
注意:到301,我的意思是永久重定向。
答案 0 :(得分:0)
我自己想通了。 写下答案,以便其他人可以获益。
# Custom Redirect For HomePage
RewriteCond %{HTTP_HOST} ^oldsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com$
RewriteRule ^$ https://www.newsite.com/page1/? [L,R=301]
#Generic Redirect for the entire website
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com$
RewriteRule (.*)$ https://www.newsite.com/$1 [R=301,L]
</IfModule>
此处的序列非常重要,应先放置自定义重定向,然后再放置域的通用重定向。