.htaccess将所有流量重定向到一个页面(410 Gone)

时间:2009-12-29 17:48:27

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

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

我已经阅读过关于可能使用HTTP 410 Gone作为从技术上向机器人解释的最佳方式,该网站不在那里,没有回来而且没有提供转发地址。在.htaccess文件中执行此操作的最佳方法是什么,并将用户定向到新的index.html?

3 个答案:

答案 0 :(得分:10)

您可以使用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之后可用。

答案 1 :(得分:4)

你可以简单地使用这样的.htaccess文件:

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

答案 2 :(得分:0)

这更简单:

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

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

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