我的网站是 HTML/CSS/JS 网站,没有服务器(静态网站(位于 MS Azure 上。 我最近像这样更改了 2 个 html 文件:
www.mydomain.com/oldfile1.html
www.mydomain.com/oldfile2.html
自
www.mydomain.com/newfile1.html
www.mydomain.com/newfile2.html
考虑到网站是静态的并且 .htaccess 不起作用,并且似乎在 html 文件中使用 meta 标记不被视为 301 永久重定向,我如何为了 SEO 重定向旧 URL?!
301 重定向是服务器端指令。
您放置在客户端文件(<meta>
/javascript
(中的任何内容在文件到达浏览器之前无法被浏览器读取。
此时,执行服务器端指令为时已晚。
您现在将浏览器指向您尝试
指向的目标。可能不是最好的答案,但您可以更改旧文件的 html 以重定向到新文件。
所以像这样:
<html>
<head>
<!--Tells search engines to not index this page-->
<meta name="robots" content="noindex">
<!--Redirect to new resource-->
<meta http-equiv="Refresh" content="0; url=www.mydomain.com/newfile1.html">
</head>
<body>
<!--In case both JavaScript and the meta tag fail-->
<p>If you aren't automatically redirected please follow<a href="www.mydomain.com/newfile1.html">this link</a>.</p>
<script>
//JavaScript fallback if browser does not support/allow http-equiv="Refresh"
window.location = 'www.mydomain.com/newfile1.html'
</script>
</body>
</html>