Redirect in PHP
Redirecting pages in PHP
To make the user when accessing a particular address of your site be redirected to another address, inside or outside your site, you must use the Location: parameter of the header() function. Below is an example of basic use of this function:
The way it is above, whenever the user accesses the page containing the above code, it will automatically redirect to http://www.seusite.com.br/pasta.
Redirecting is not restricted to absolute addresses of websites, and you can also redirect to folders within your FTP, or even files that are in the same folder using a path relative to it.
To better illustrate this, we will create a script that will capture the address you are accessing, and redirect the user to another as per this access address.
Remembering that for the above script to work, all entries used in the script must be created in DNS.
Usually when specifying the server folder you want to access, Exp: "www.test/pasta1/subfolder" the server already automatically redirects to the page you are on as
index.html // index.php // index.asp
, ai depends on the server implementation....– MarceloBoni
I understand, but in my house it’s not working, what can I do?
– Eduardo F. Santos
Depends on which server you are using.
– MarceloBoni
@Eduardof.Santos you are using Apache?
– Jéf Bueno