如何将所有网络流量重定向到特定页面?

时间:2009-10-28 00:27:58

标签: php redirect traffic

有没有办法将我网站的所有流量重定向到特定网页?我的免费主机支持PHP。不确定这是否适用于此。谢谢。

5 个答案:

答案 0 :(得分:2)

如果您的主机基于Apache并支持mod_rewrite,请使用它。例如。 wordpress典型的重写,将请求重定向到不存在的文件/文件夹到index.php,传递原始URL:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

答案 1 :(得分:1)

如果您的主机运行Apache并支持.htaccess,请将此行添加到.htaccess文件

ErrorDocument 404 /index.htm

它不需要mod_rewrite。它假设只有的文件才会重定向到index.htm。

答案 2 :(得分:0)

我不确定,但元刷新可能对您有用

<META http-equiv="refresh" content="0;URL=http://some-url.com/some-page.html">

答案 3 :(得分:0)

如果你不能使用.htaccess或mod_rewrite不可用,你可以使用一个简单的PHP文件:

的index.php

<?php
header("Location: http://www.example.com/page");
?>

答案 4 :(得分:0)

您必须返回带有状态代码 301-308 的重定向标头。 只考虑使用301,因为使用301时浏览器会缓存它

<?php
   header("Location: http://www.example.com/about.php",true,302);
   exit;
?>