javascript - 重定向后根 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。
解决方案
您应该考虑通过 .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。
推荐阅读
- c++ - -march=native 有害的原因是什么
- openlayers - 选择要素时的 OpenLayers 弹出表单
- c++ - 用于在 Linux 上管理 Internet 连接的 C/C++ 库
- testing - 在 Verilog 中运行测试的问题
- python - 在 Python 中使用 requests.get 检索 API 数据时,会不断向我发回 Django 视图中完全相同的一批数据
- reactjs - 类型反应上不存在属性 x
- c# - ConnectionString 属性尚未初始化。随着使用
- node.js - 在 TSX 中访问数组的元素
- javascript - Fetch within promise,零星的反向链序
- .net-core - 使用 openiddict 设置登录页面绝对 URL 的 SSO