[英]Redirect entire website to a new website's homepage in php
Can anyone help me how to write a redirect in php. 任何人都可以帮助我如何在php中编写重定向。 I want to redirect a website and all of it's pages to a new website's homepage.
我想将网站及其所有页面重定向到新网站的主页。 From the old website I don't want to redirect the (
www.oldwebsite.com/administrator/
) page. 我不想从旧网站重定向(
www.oldwebsite.com/administrator/
)页面。
My old redirect was: 我以前的重定向是:
<?php
header("Location: http://www.newwebsite.ro");
?>
This was not good because when I clicked on ( www.oldwebsite.com/a/b
) it redirected me to ( www.newwebsite.ro/404error
) and I didn't want that. 这不是很好,因为当我单击(
www.oldwebsite.com/a/b
)时,它将我重定向到( www.newwebsite.ro/404error
),而我并不想那样。
How should I do it right? 我该怎么做呢?
You should use die() or exit() after header 您应该在标头后使用die()或exit()
header("Location: http://example.com/myOtherPage.php");
die();
You can use htaccess to redirect from old domain to new. 您可以使用htaccess从旧域重定向到新域。 Here is example:
这是示例:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.