域名跳转,也称为URL重定向,是一种将用户从一个域名(或子域名)引导到另一个域名的技术。这在多种场景下非常有用,例如网站迁移、品牌变更、负载均衡等。
域名跳转可以通过多种方式实现,包括:
RewriteEngine On
RewriteRule ^old-domain-url$ https://new-domain.com/new-url [R=301,L]
server {
server_name old-domain.com;
return 301 $scheme://new-domain.com$request_uri;
}
<?php
header('Location: https://new-domain.com/new-url', true, 301);
exit();
?>
const express = require('express');
const app = express();
app.get('/old-path', (req, res) => {
res.redirect(301, 'https://new-domain.com/new-path');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
请注意,以上代码示例和配置可能需要根据实际情况进行调整。
领取专属 10元无门槛券
手把手带您无忧上云