【问题标题】:.htaccess to Redirect All Traffic to One Page (410 Gone).htaccess 将所有流量重定向到一页 (410 Gone)
【发布时间】:2010-12-30 20:38:38
【问题描述】:

我们有一个客户正在关门。我们希望将进入其域的所有流量重定向到新页面 index.html,其中 _img 子目录中有一些图像。 (该页面解释了发生的事情、当前客户对当前订单的期望等)

我读到过可能使用 HTTP 410 Gone 作为向机器人等技术解释该站点不存在、不返回且不提供转发地址的最佳方式。在 .htaccess 文件中执行此操作并将用户引导到新的 index.html 的最佳方法是什么?

【问题讨论】:

标签: apache .htaccess http redirect http-status-code-410


【解决方案1】:

您可以为此使用mod_rewrite

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.html$ index.html [L,R=410]

此规则会将对不存在文件的请求重写为index.html,并与响应一起发送 410 状态代码。但这需要 Apache 2,因为 R=4xx 自 Apache 2 起才可用。

【讨论】:

  • R=4xx 在浏览器中工作吗?我尝试过一次,但无法正常工作,但可能我使用的是 Apache 1.3。
  • @ceejayoz:一切都在服务器端内部完成。客户端只是得到响应。
  • 如果像我一样,R=410 给出 Apache 错误,请尝试使用
【解决方案2】:

您可以像这样简单地使用 .htaccess 文件:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !.*index\.php
   RewriteRule (.*) /index.php
</IfModule>

【讨论】:

    【解决方案3】:

    这要简单得多:

    RedirectMatch temp .* http://www.newdomain.com/newdestination.html
    

    它将每个请求重定向到 newdestination.html。

    请注意,如果您指向与源相同的域,则会出现无限循环并且这将失败。不过,这非常适合指向一个新域。

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2014-01-11
      • 1970-01-01
      • 2017-08-13
      相关资源
      最近更新 更多