我有example.com
,我可以将其重定向到home.example.com
使用:
RewriteEngine On
RewriteRule (.*) https://home.example.com/$1 [R=301,L]
但我想做的另一部分是将所有其他URL重定向到一个新的域。
像https://example.com/interestingblogpost
一样重定向到https://another.example/interestingblogpost
。
不管有什么建议,我在搜索中似乎找不到任何东西。
哦,这是一个WordPress网站。
您当前的指令已经将所有URL重定向到另一个主机名(主域的子域(。
如果你需要进行特定的重定向,那么你只需要将这些放在你当前的指令之前。也就是说,大多数特定的重定向应该是第一个。
例如:
RewriteEngine On
# Specific redirects...
RewriteRule ^interestingblogpost$ https://another.example/$0 [R=301,L]
# Redirect everything else to home.example.com
RewriteRule (.*) https://home.example.com/$1 [R=301,L]
假设该.htaccess
文件仅服务于example.com
,则上述操作将把https://example.com/interestingblogpost
重定向到https://another.example./interestingblogpost
。
CCD_ 9是用于整个匹配图案的反向参考。
在测试之前,您需要清除浏览器缓存,因为重定向所有的早期301可能已经缓存(如果您之前请求过/interestingblogpost
(。出于这个原因,通常最好先用默认情况下不缓存的302(临时(重定向进行测试。