3

我在我的网站上更改了一些文件名,现在我想将“301 永久移动”从旧文件重定向到新文件。

问题是我的网站完全由静态 html 页面组成,所有 301 重定向教程都描述了如何在 PHP、ASP、htaccess 等中进行操作。我想将重定向直接写入旧的 html 文件,这可能吗?还是我必须联系我的网络提供商并解决服务器上的重定向问题?

我对服务器的唯一了解是它在 Windows 上运行,而我对服务器一无所知。

编辑:我的虚拟主机使用的是 Microsoft IIS 7.0,所以我认为这里无法使用 .htaccess?

编辑#2:刚才我的服务器管理员写信给我,即使我只使用静态 HTML 页面,我仍然可以使用 web.config 文件来重定向单个 html 文件。这是非常好的。

4

4 回答 4

5

您不能使用 HTML 更改 HTTP 状态代码。

但如果您使用的是 Apache 网络服务器,则可以使用mod_rewritemod_alias将此类请求重定向到新地址:

# mod_rewrite
RewriteEngine on
RewriteRule ^old\.html$ /new.html [L,R=301]

# mod_alias
RedirectMatch 301 ^/old\.html$ /new.html

编辑   正如您现在澄清您使用的是 IIS 7 一样,请查看其<httpRedirect>用于 HTTP redirects 的元素

于 2009-06-01T10:59:01.440 回答
3

不,这是不可能的。服务器不处理 HTML,因此无法设置 HTTP 标头。

您应该改为查看 Apache 配置(例如,使用 .htaccess)。

简单地说,您可以这样做:

  Redirect 301 old.html http://example.com/new/
  Redirect 301 other-old.html http://example.com/newer/
于 2009-06-01T11:01:02.480 回答
2

我想您可以使用 JavaScript 和/或元刷新(如 Gumbo 建议的那样)将用户从旧页面重定向到新页面。就像是:

<html>
<head>
  <meta http-equiv="refresh" content="0;url=http://YourServer/NewFile.html" />

  <script type="text/javascript">
    location.replace('http://YourServer/NewFile.html');
  </script> 
</head>
<body>
  This page has moved. <a href="http://YourServer/NewFile.html">Click here for the new location</a>
</body>
</html>
于 2009-06-01T11:09:44.057 回答
-1

在 IIS 中重定向单个页面是一件简单的事情,并在您的 web.config 文件中完成。

  <location path="products.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://yourserver/products" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
于 2020-01-26T02:54:18.620 回答