代码之家  ›  专栏  ›  技术社区  ›  user

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

  •  1
  • user  · 技术社区  · 16 年前

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

    4 回复  |  直到 16 年前
        1
  •  2
  •   Remus Rusanu    16 年前

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

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
        2
  •  1
  •   bmb    16 年前

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

    ErrorDocument 404 /index.htm
    

    它不需要修改。它假定只有 找到的将重定向到index.htm。

        3
  •  0
  •   FrustratedWithFormsDesigner    16 年前

    我不确定,但元刷新可能适合你

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

        4
  •  0
  •   Peter Sankauskas    16 年前

    如果无法使用.htaccess或mod_rewrite不可用,可以使用简单的PHP文件:

    index.php

    <?php
    header("Location: http://www.example.com/page");
    ?>
    
        5
  •  0
  •   Abilogos    5 年前

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

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