0

I have a php form that i have on one domain. If i copy all files to another domain. How can i change my redirect so it goes to index.php in the same folder? So if i copy all files to another folder or domain, it will work without any editing.

This how it looks today.

/* Redirect browser */

header("Location: http://my_domain.com/Folder/"); /* Make sure that code below does not get executed when we redirect. */

So if i copy all files to http://my_domain.com/app/

  • Perhaps you are looking for [\_\_DIR\_\_](https://www.php.net/manual/en/language.constants.magic.php) or one of the [\_SERVER](https://www.php.net/manual/en/reserved.variables.server.php) values, in PHP? Something that changes when you move the file around on your server. – KIKO Software Aug 05 '21 at 05:08
  • Please share more details. Why do you need this after all? Why not configure your webserver itself properly? Also, please do not use irrelevant tags - otherwise explain how this is related to forms or browser – Nico Haase Aug 05 '21 at 07:53
  • Does this answer your question? [Header Location relative path compatibility](https://stackoverflow.com/questions/10541439/header-location-relative-path-compatibility) – Markus Aug 05 '21 at 10:36

1 Answers1

0

One way to deal with this would be to use relative path but since you have hardcoded your domain, you could replace it with $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST'] ($_SERVER). You can then use something like this:

header("Location: http://".$_SERVER['HTTP_HOST']."/Folder/");