How to redirect all web traffic to a specific page?

蹲街弑〆低调 提交于 2019-12-02 06:50:35

问题


Is there a way to redirect all traffic to my website to a specific page? My free host does support PHP. Not sure if that is what would be appropriate for this or not. Thank you.


回答1:


If your host is based on Apache and supports mod_rewrite, use that. Eg. the wordpress typical rewite, that redirects requests to non-existing files/folders to index.php, passing on the original URL:

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



回答2:


If your host runs Apache and supports .htaccess, add this line to your .htaccess file

ErrorDocument 404 /index.htm

It does not require mod_rewrite. It does assume that only files that are not found will redirect to index.htm.




回答3:


I'm not sure but meta refresh might work for you

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




回答4:


If you can't use .htaccess or mod_rewrite is not available, you can use a simple PHP file:

index.php

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


来源:https://stackoverflow.com/questions/1634511/how-to-redirect-all-web-traffic-to-a-specific-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!