How to redirect in php

To send the browser to a new URL, known as a redirection, you set the Location header. Generally, you’ll also immediately exit afterwards, so the script doesn’t bother generating and outputting the remainder of the code listing:


When you provide a partial URL (e.g., /elsewhere.html), the web server handles this redirection internally. This is only rarely useful, as the browser generally won’t learn that it isn’t getting the page it requested. If there are relative URLs in the new document, the browser interprets those URLs as being relative to the requested document, rather than to the document that was ultimately sent. In general, you’ll want to redirect to an absolute URL

Leave a Comment