What are the best practices for setting up multiple domains to point to the same content on a PHP server using DNS records and aliases?
When setting up multiple domains to point to the same content on a PHP server, you can use DNS records to point all the domains to the same server IP address and then use aliases in your server configuration to handle the different domain names. This allows you to serve the same content for multiple domains without duplicating files or code.
<?php
// Get the current host name
$host = $_SERVER['HTTP_HOST'];
// Define an array of allowed domain names
$allowed_domains = array('domain1.com', 'domain2.com', 'domain3.com');
// Check if the current host is in the allowed domains
if (in_array($host, $allowed_domains)) {
// Serve the content for the specified domain
include 'content.php';
} else {
// Redirect to a default domain or show an error message
header('Location: http://defaultdomain.com');
exit;
}
?>