簡體   English   中英

example.herokuapp.com 重定向到 example.com - PHP

[英]example.herokuapp.com redirection to example.com - PHP

背景

我有一個基本的 PHP 應用程序部署在 Cloudflare 的 Heroku、DNS 上。

問題

即使在我設置了自定義域之后,我的應用程序的 Heroku 域仍然處於活動狀態。 我希望用戶專門使用自定義域。 換句話說,我的目標是:當用戶訪問example.herokuapp.com時,將他們發送到mydomain.com

Heroku 說這樣做:

您的應用應發送HTTP status 301 Moved Permanently以告知 web 瀏覽器使用自定義域。 主機 HTTP 請求 header 字段將顯示用戶正在嘗試訪問的域; 如果該字段是example.herokuapp.com ,則發送重定向。

我是 PHP 的新手(我是 Node.js 人),所以我不知道該怎么做。

我的 PHP 項目只有 2 個文件: index.htmlindex.php看起來像

/* index.php */

<?php include 'index.html';?>

當您提供重定向時,您需要省略正文。

/* index.php
 * Redirect to example.com
 */

<?php
header("Location: https://example.com", TRUE, 301);
exit;
?>

您有 2 個選項,您可以在服務器級別重定向(可能是 apache 或 nginx 取決於您使用的內容),或者您可以使用 php 重定向。 我會推薦通過seever,因為這樣會更安全、更快捷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM