首页 > 解决方案 > 重定向后根 URL 没有被更改?

问题描述

我有两个网址。网址一:https ://www.website.com/blue/dog.htm#cat

和网址 B:https ://www.website.com/blue/en-us/dog.htm#cat

在后端,文件夹结构最初是/blue/dog.htm/但我添加了一个新文件夹 /en-us/ 所以现在 URL B 的结构是/blue/en-us/dog.htm/

我可以进行简单的重定向,但我不确定如何将路径添加到 URL 的中间,尤其是当 URL A 的文件路径不再存在时。

<!DOCTYPE html>
<html>
<head>
<script>
window.location.href = '/blue/en-us/';
</script>
</head>

问题是,我已经将https://www.website.com/blue/dog.htm#cat放到了一些外部网站上,现在它们没有重定向到新的 URL。

标签: javascripthtmlredirect

解决方案


您应该考虑通过 .htaccess 使用 301 重定向。

见这里:https ://moz.com/learn/seo/redirection

您可以像这样定义您的 301:

RedirectMatch 301 /seo/someoldfile.php http://www.seomoz.org

/seo/someoldfile.php旧网址,http://www.seomoz.org是新位置。

所以你会这样做:

RedirectMatch 301 https://www.website.com/blue/dog.htm#cat https://www.website.com/blue/en-us/dog.htm#cat

因此,当用户登陆链接 A 时,他们将被推送到链接 B。


推荐阅读