Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to a different domain in PHP

I am trying to redirect www.xyz.com/my to www.abc.com, how can I do this in PHP?

like image 454
Rahul Gupta Avatar asked Sep 16 '25 23:09

Rahul Gupta


1 Answers

Strictly speaking you need to send a HTTP location header to the clients browser.

To do this in PHP, as the other answers have mentioned is to use the header() function.

header("Location: http://www.abc.com");

There is a caveat that you should be aware of. The most common problem people encounter when dealing with HTTP headers is that they must be sent to the browser prior to any other data. If you echo any content to the client and then try to send the location header, it wont work.

For reference, there are many other HTTP headers that you should familiarize your self with.

like image 126
hafichuk Avatar answered Sep 19 '25 14:09

hafichuk