You can use a PHP script to redirect a domain to a new URL. To do this, you will need to create a PHP file with the following code:
<?php header("Location: new_url"); exit; ?>
Replace "new_url" with the URL that you want to redirect to.
You can then upload this PHP file to your web server and make it the default index file (e.g., index.php
) for the domain that you want to redirect. When a user accesses the domain, the PHP script will execute and redirect the user to the specified URL.
You can also use the header
function to specify the HTTP status code to use for the redirect. For example, to redirect the user using a 301 Moved Permanently status code, you can use the following code:
<?php header("Location: new_url", true, 301); exit; ?>
Using a 301 status code can help search engines understand that the domain has permanently moved to the new URL, which can be useful for SEO purposes.
Keep in mind that the PHP script will only redirect users who access the domain using a web browser. It will not redirect other types of traffic, such as email or FTP. If you want to redirect all traffic to the domain, you will need to use a different method, such as configuring the domain's DNS records to point to the new URL.