To redirect all pages of a website hosted on nginx to another domain using PHP, you can use the following rewrite rule in your nginx configuration file:
115 chars7 lines
This will redirect all requests to your-domain.com to https://new-domain.com with a 301 status code, indicating a permanent redirection.
Make sure to replace your-domain.com
and new-domain.com
with your own domain names.
You'll also need to make sure that PHP is properly installed and configured on your server. Once it is, you can create a index.php
file with a 301 redirect like this:
main.php127 chars6 lines
This PHP code will send a 301 header with the new domain name and the requested URI, effectively redirecting all pages of the website to the new domain.
Note that this approach will only work if your server is properly configured to use PHP files.
gistlibby LogSnag