Webserver on Arduino: How to 307 temporary redirect
You need to make a decision on what to respond with depending on what the request is you have received.

If you receive a "command" URL (which you already check for by looking for certain sub-strings) then you need to respond with the 307 response. If you don't receive a "command" URL (so anything except the things you are specifically looking for) then you respond with the homepage.

A slight re-formatting of your decision code to use else if instead of just if would make it easier:

if (c == '\n') {
  Serial.println(readString); //print to serial monitor for debuging
  // homepage(); &lt;&lt; This is now moved elsewhere.
  //controls the Arduino if you press the buttons
  if (readString.indexOf("?resetcount1") &gt; 0) {
    count1 = 0;
    redirect();
  } else if (readString.indexOf("?resetcount2") &gt; 0) {
    count2 = 0;
    redirect();
  } else if (readString.indexOf("?resetcount3") &gt; 0) {
    count3 = 0;
    redirect();
  } else if (readString.indexOf("?resetcount4") &gt; 0) {
    count4 = 0;
    redirect();
  } else if (readString.indexOf("?togglerelay1") &gt; 0) {
    toggleRelay1();
    redirect();
  } else if (readString.indexOf("?togglerelay2") &gt; 0) {
    toggleRelay2();
    redirect();
  } else if (readString.indexOf("?togglerelay3") &gt; 0) {
    toggleRelay3();
    redirect();
  } else if (readString.indexOf("?togglerelay4") &gt; 0) {
    toggleRelay4();
    redirect();
  } else { // If none of them match then send the homepage.
    homepage();
  }
}


redirect() is as simple as:

void redirect() {
  client.println("HTTP/1.1 307 Temporary Redirect");
  client.println("Location: /");
  client.println("Connection: Close");
  client.println();
  client.stop();
}