我需要在 NextJS 中从旧域(looshes.com)移动到新域(looshes.co.il)。我该怎么做?

问题描述 投票:0回答:0

我尝试了很多东西,例如:

export async function getServerSideProps({ req, res }: any) {
  if (req.headers.host === 'looshes.com') {
    res.setHeader('Location', 'https://looshes.co.il' + req.url);
    res.statusCode = 301;
    res.end();
    return { props: {} };
  }

  return {
    props: {},
  };
}

或:

  useEffect(() => {
    if (window.location.hostname === 'looshes.com') {
      router.push('https://looshes.co.il' + router.asPath, undefined, { shallow: true });
    }
  }, [router]);

但对我没有任何用处。

javascript node.js next.js http-redirect
© www.soinside.com 2019 - 2024. All rights reserved.