Reputation:
Background:
I have a basic PHP app deployed on Heroku, DNS by Cloudflare.
Problem:
My app’s Heroku domain is still active, even after I set up a custom domain. I want users to use the custom domain exclusively. In other words, my goal is: When users visit example.herokuapp.com
, send them to mydomain.com
.
Heroku says to do this:
Your app should send HTTP status 301 Moved Permanently to tell web browsers to use the custom domain. The Host HTTP request header field will show which domain the user is trying to access; send a redirect if that field is
example.herokuapp.com
.
I'm new to PHP (I'm a Node.js person) so I don't understand what to do.
My PHP project is only 2 files: index.html
and index.php
which looks like
/* index.php */
<?php include 'index.html';?>
Upvotes: 1
Views: 167
Reputation: 1945
You have 2 options, either you can redirect at server level ( may be you apache or nginx depends on whta youbare using) or you can redirect with php. I would recommend via seever as this will be more safe and quick.
Upvotes: 0
Reputation: 79
When you're serving a redirect, you need to omit the body.
/* index.php
* Redirect to example.com
*/
<?php
header("Location: https://example.com", TRUE, 301);
exit;
?>
Upvotes: 0