重定向 php_如何使用PHP重定向

重定向 php

A PHP forwarding script is useful if you want to redirect one page to another so that your visitors can reach a different page than the one they land on.

如果您要将页面重定向到另一页面 ,以便访问者可以访问的页面不同于他们访问的页面 ,则PHP转发脚本很有用。

Fortunately, it's really easy to forward with PHP. With this method, you seamlessly transfer visitors from the web page that no longer exists to the new page without requiring them to click a link to continue.

幸运的是,使用PHP进行转发确实很容易。 使用此方法,您可以将访问者从不再存在的网页无缝地转移到新页面,而无需他们单击链接以继续。

如何使用PHP重定向 ( How to Redirect With PHP )

On the page that you want to redirect elsewhere, change the PHP code to read like this: 

在您要重定向到其他位置的页面上,将PHP代码更改为如下所示:

The header() function sends a raw HTTP header. It must be called before any output is sent, either by normal HTML tags, by PHP, or by blank lines.

header()函数发送原始HTTP标头。 必须先通过常规HTML标记,PHP或空白行发送任何输出,然后调用它。

Replace the URL in this sample code with the URL of the page where you want to redirect visitors. Any page is supported, so you can transfer visitors to a different webpage on your own site or to a different website entirely.

将此示例代码中的URL替换为您要重定向访问者的页面的URL。 支持任何页面,因此您可以将访问者转移到您自己网站上的其他网页或完全转移到其他网站。

Because this includes the header() function, be sure that you do not have any text sent to the browser before this code, or it will not work. Your safest bet is to remove all the content from the page except for the redirect code.

因为它包括header()函数,所以请确保在此代码之前没有任何文本发送到浏览器,否则它将无法工作。 最安全的选择是从页面上删除除重定向代码以外的所有内容。

何时使用PHP重定向脚本 ( When to Use a PHP Redirect Script )

If you remove one of your web pages, it's a good idea to set up a redirect so that anyone who bookmarked that page is transferred automatically to an active, updated page on your website. Without the PHP forward, visitors would remain on the dead, broken, or inactive page.

如果您删除一个网页,则最好设置重定向,以便将添加了书签的任何人自动转移到您网站上活动的,更新的页面上。 如果没有PHP前进,访问者将停留在不活动,损坏或不活动的页面上。

The benefits of this PHP script are as follows:

此PHP脚本的优点如下:

  • Users are redirected quickly and seamlessly.

    快速无缝地重定向用户。
  • When the Back button is clicked, visitors are taken to the last viewed page, not the redirect page.

    单击“ 后退”按钮时,访问者将被带到上次查看的页面,而不是重定向页面。

  • The redirect works on all web browsers.

    重定向适用于所有Web浏览器。

设置重定向的提示 ( Tips for Setting up a Redirect )

  • Remove all code but this redirect script.

    删除所有代码,但删除此重定向脚本。
  • Mention on the new page that users should update their links and bookmarks.

    在新页面上提到用户应更新其链接和书签。

  • Use this code to create a drop-down menu that redirects users.

    使用此代码创建一个重定向用户的下拉菜单。

翻译自: https://www.thoughtco.com/how-to-redirect-with-php-2693922

重定向 php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值