You could also use the following code:

header("Location: //www.google.com");
Answer from user1756209 on Stack Overflow
🌐
PHP
php.net › manual › en › function.header.php
PHP: header - Manual
Found on https://en.wikipedia.org/wiki/HTTP_location «An obsolete version of the HTTP 1.1 specifications (IETF RFC 2616) required a complete absolute URI for redirection.[2] The IETF HTTP working group found that the most popular web browsers tolerate the passing of a relative URL[3] and, consequently, the updated HTTP 1.1 specifications (IETF RFC 7231) relaxed the original constraint, allowing the use of relative URLs in Location headers.» ·
Discussions

PHP header location to https - Stack Overflow
Instead use the HTTPS scheme to access this URL, please. What do I have to change? What did I do wrong or what do I have to add? ... This sounds absurd but after some thinking: I added a slash (/) at the end so now it looks like this header('Location: '.PROJECT_HTTP_ROOT.'/');. More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
Redirecting from HTTP to HTTPS with PHP - Stack Overflow
I'm working on a shopping cart website and I would like to redirect the user to a HTTPS page when he's entering his billing details and maintain the HTTPS connection for the next pages until he log... More on stackoverflow.com
🌐 stackoverflow.com
PHP header(location) function not working
Once you output any content (an echo statement, or white space or text outside of PHP), then you can no longer modify the header information. Someone posted a similar problem recently, with a link to a good explanation on Stack Overflow: https://teamtreehouse.com/forum/redirecting-after-a-... More on teamtreehouse.com
🌐 teamtreehouse.com
16
April 12, 2013
$_SESSION data lost after header redirect
deleted 0.0128 What is ^^^this? More on reddit.com
🌐 r/PHP
22
2
June 9, 2012
🌐
Edureka
edureka.co › blog › header-location-in-php
Header Location In PHP | PHP Header Location Edureka
February 25, 2025 - It must be called before sending any actual output, either by normal HTML tags, blank lines in a file or from a PHP file. Syntax: header(string,replace,http_response_code); string: It consists of a header string. Basically, there are two types of header calls. One is header which starts with string “HTTP/” used to figure out the HTTP status code to send. Another one is the “Location” which is mandatory.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-make-a-redirect-in-php
How to make a redirect in PHP? - GeeksforGeeks
July 12, 2025 - <?php // Redirect browser header("Location: https://www.geeksforgeeks.org/"); exit; ?> Note: The die() or exit() function after header is mandatory. If die() or exit() is not put after the header('Location: ....') then script may continue resulting in unexpected behavior.
🌐
HubSpot
blog.hubspot.com › home › website › how to redirect in php: what you need to know
How to Redirect in PHP: What You Need to Know
May 13, 2025 - First, remember where you place the header() function in your index.php file isn’t arbitrary. Second, recall that you may choose to set HTTP status codes. These will control how the server redirects a search engine or user. In order for your PHP redirect to be successful, the header() function must execute — and before any output is sent.
🌐
PHPpot
phppot.com › php › php-header
PHP header - PHPpot
The header location redirects users to the target URI and returns the 302 status code to the client. It is to replace the header property already defined. This is an optional parameter having boolean true as a default value. It overrides the defined header settings by default. We can turn the default behavior off by setting false to this parameter. <?php header('WWW-Authenticate: Negotiate'); echo ('header WWW-Authenticate is set to Negotiate \n'); header('WWW-Authenticate: NTLM', false); echo ('header WWW-Authenticate is changed to NTLM'); ?>
Find elsewhere
🌐
Elementor
elementor.com › blog › resources › php redirects: how to make a redirect in php? {8 methods}
PHP Redirects: How to Make a Redirect in PHP? {8 Methods}
November 30, 2025 - Use case: Website maintenance, short-term content changes. ... header("Location: https://www.example.com/"): This sends the “Location” header, instructing the browser where to redirect the user.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-header-function
PHP | header() Function - GeeksforGeeks
July 11, 2025 - The second case of header is the "Location:". It is mandatory parameter. $replace: It is optional parameter. It denotes the header should replace previous one or add a second header. The default value is True (will replace). If $replace value is False then it force multiple headers of the same type. $http_response_code: It is an optional parameter. It forces the HTTP response code to the specified value (PHP 4.3 and higher).
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 358490 › header-location-php-help
Header location php (help) | DaniWeb
April 8, 2011 - You were tripping over three separate issues: 1) misuse of the header() call (it should send a plain URL string — not an HTML anchor), 2) session_start() / header() must run before any browser output (including stray whitespace or a BOM), and 3) base64/urlencode only obfuscates a link — it does not protect it. @cwarn23 already pointed out the <?php vs <? and header/output ordering, and @happytogether’s ob_start() is a workable fallback; the long-term fix is to eliminate any output before session or header calls and save files as UTF‑8 without BOM.
🌐
W3Schools
w3schools.in › php › php-headers
PHP Header Function - W3Schools
<?php header("Location: http://www.example.com/"); ?>
🌐
Tutorialspoint
tutorialspoint.com › php › php_function_header.htm
PHP Network header() Function
Below is the syntax of the PHP Network header() function − · void header ( string $header, bool $replace, int $res_code ) Here are the parameters of the header() function − · $header − (Required) The exact header text to send, like "Location: URL" or "HTTP/1.1 404 Not Found."
🌐
W3Schools
w3schools.com › php › func_network_header.asp
PHP header() Function
Let the user be prompted to save a generated PDF file (Content-Disposition header is used to supply a recommended filename and force the browser to display the save dialog box): <?php header("Content-type:application/pdf"); // It will be called downloaded.pdf header("Content-Disposition:attachment;filename='downloaded.pdf'"); // The PDF source is in original.pdf readfile("original.pdf"); ?> <html> <body> ...
🌐
Wikipedia
en.wikipedia.org › wiki › HTTP_location
HTTP location - Wikipedia
October 17, 2025 - The HTTP Location header field is returned in responses from an HTTP server under two circumstances: To ask a web browser to load a different web page (URL redirection). In this circumstance, the Location header should be sent with an HTTP status ...
🌐
Content-Security-Policy
content-security-policy.com › examples › php
Content-Security-Policy PHP Examples
Here's how to use PHP to add a Content-Security-Policy HTTP response header to your site.
🌐
Hostinger
hostinger.com › home › tutorials › how to make a php redirect
How to make a PHP redirect
November 19, 2025 - To perform a redirect in PHP with specific HTTP status codes like 301 or 302, you add the status code as an optional parameter to the header() function. By default, header(‘Location: …’) sends a 302 temporary redirect. To add a specific code, you use the function’s optional parameters: header(“Location: URL”, true, 301).