user26276: It's been days that I'm trying to figure it out how to edit this perfectly working code in order to load load a webpage from the sd card.
#include <SPI.h>
#include <Ethernet2.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte ip[] = { 192, 168, 1, 178 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 };                   // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
EthernetServer server(80);                             //server port     
String readString;
boolean L1chk;
boolean L2chk;
boolean L3chk;
boolean L4chk;
boolean L5chk;
boolean L6chk;
boolean L7chk;
boolean L8chk;
int led;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
         }

         //if HTTP request has ended
         if (c == '\n') {          
           Serial.println(readString); //print to serial monitor for debuging

           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<HEAD>");
           client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<TITLE>CONTROLLO LEDS</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>FLASHATI</H1>");
           client.println("<hr />");
           client.println("<a href=\"/?1\"\">LED1</a>");
           client.println("<a href=\"/?2\"\">LED2</a>");
           client.println("<a href=\"/?3\"\">LED3</a>");
           client.println("<a href=\"/?4\"\">LED4</a>");
           client.println("<a href=\"/?5\"\">LED5</a>");
           client.println("<a href=\"/?6\"\">LED6</a>");
           client.println("<a href=\"/?7\"\">LED7</a>");
           client.println("<a href=\"/?8\"\">LED8</a>");
           client.println("<br />");     
           client.println("<br />"); 
           client.println("<p>Created by Rui Santos. Visit http://randomnerdtutorials.com for more projects!</p>");  
           client.println("<br />"); 
           client.println("</BODY>");
           client.println("</HTML>");

           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?1") >0){
               ledUno();
            }
           if (readString.indexOf("?2") >0){
               ledDue();
            }
            if (readString.indexOf("?3") >0){
               ledTre();
            }
            if (readString.indexOf("?4") >0){
               ledQuattro();
            }
            if (readString.indexOf("?5") >0){
               ledCinque();
            }
            if (readString.indexOf("?6") >0){
               ledSei();
            }
            if (readString.indexOf("?7") >0){
               ledSette();
            }
            if (readString.indexOf("?8") >0){
               ledOtto();
            }
           readString="";
        }

        }
    }
}
}

So I came out with this after a lot of research:
/*
    Created by Rui Santos
    Visit: http://randomnerdtutorials.com for more arduino projects

    Arduino with Ethernet Shield
*/

#include <SPI.h>
#include <Ethernet2.h>
#include <SD.h>
File webFile;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte ip[] = { 192, 168, 1, 178 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 };                   // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
EthernetServer server(80);                             //server port     
String readString;
boolean L1chk;
boolean L2chk;
boolean L3chk;
boolean L4chk;
boolean L5chk;
boolean L6chk;
boolean L7chk;
boolean L8chk;
int led;

void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);

    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    // start the Ethernet connection and the server:
    Ethernet.begin(mac);
    server.begin();
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
}


void loop() {
    // Create a client connection
    EthernetClient client = server.available();
    if (client) {
        boolean currentLineIsBlank = true;
        while (client.connected()) {   
            if (client.available()) {
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    webFile = SD.open("index.htm");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }

                        webFile.close();
                    }
                    break;

                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                    if (readString.indexOf("?1") >0){
                        ledUno();
                    }
                    if (readString.indexOf("?2") >0){
                        ledDue();
                    }
                    if (readString.indexOf("?3") >0){
                        ledTre();
                    }
                    if (readString.indexOf("?4") >0){
                        ledQuattro();
                    }
                    if (readString.indexOf("?5") >0){
                        ledCinque();
                    }
                    if (readString.indexOf("?6") >0){
                        ledSei();
                    }
                    if (readString.indexOf("?7") >0){
                        ledSette();
                    }
                    if (readString.indexOf("?8") >0){
                        ledOtto();
                    }
                    readString="";
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
                //controls the Arduino if you press the buttons

            }

        }
        delay(1);      // give the web browser time to receive the data
        client.stop();
        if (readString.indexOf("?1") >0){
            ledUno();
        }
        if (readString.indexOf("?2") >0){
            ledDue();
        }
        if (readString.indexOf("?3") >0){
            ledTre();
        }
        if (readString.indexOf("?4") >0){
            ledQuattro();
        }
        if (readString.indexOf("?5") >0){
            ledCinque();
        }
        if (readString.indexOf("?6") >0){
            ledSei();
        }
        if (readString.indexOf("?7") >0){ 
            ledSette();
        }
        if (readString.indexOf("?8") >0){
            ledOtto();
        }
        readString="";
    }
}


void ledUno(){
    led = 2;
    if (L1chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L1chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L1chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L1chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledDue(){
    led = 3;
    if (L2chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L2chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L2chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L2chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledTre(){
    led = 4;
    if (L3chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L3chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L3chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L3chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledQuattro(){
    led = 5;
    if (L4chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L4chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L4chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L4chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledCinque(){
    led = 6;
    if (L5chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L5chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L5chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L5chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledSei(){
    led = 7;
    if (L6chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L6chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L6chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L6chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledSette(){
    led = 8;
    if (L7chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L7chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L7chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L7chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledOtto(){
    led = 9;
    if (L8chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L8chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L8chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L8chk = 0;
        return;                   //Led 1 acceso           
    }
}

So far the web page is correctly loaded, but the sketch of the LED light logic seems to not work anymore like it was working correctly before. I thought that maybe someone of you guys could help point me in the right direction.

user26276: It looks that I found the solution to my problem, the first skecth was working correctly because  the SD card is using the pin 4  for his purpose, so the sketch was working good becuse the SD card was not used here, in the second code where I used th SD card to serve a webpage was not working anymore not because of the code, but becuse the PIN 4 where I connected a led was used by SDcard and so it messed up by blinking the LED
DON'T USE PIN4 WITH AN ETHERNET SHIELD IF YOU PLAN TO USE THE SD CARD

26276: <p>It's been days that I'm trying to figure it out how to edit this perfectly working code in order to load load a webpage from the sd card.</p>

<pre><code>#include &lt;SPI.h&gt;
#include &lt;Ethernet2.h&gt;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte ip[] = { 192, 168, 1, 178 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 };                   // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
EthernetServer server(80);                             //server port     
String readString;
boolean L1chk;
boolean L2chk;
boolean L3chk;
boolean L4chk;
boolean L5chk;
boolean L6chk;
boolean L7chk;
boolean L8chk;
int led;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() &lt; 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
         }

         //if HTTP request has ended
         if (c == '\n') {          
           Serial.println(readString); //print to serial monitor for debuging

           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("&lt;HTML&gt;");
           client.println("&lt;HEAD&gt;");
           client.println("&lt;meta name='apple-mobile-web-app-capable' content='yes' /&gt;");
           client.println("&lt;meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' /&gt;");
           client.println("&lt;TITLE&gt;CONTROLLO LEDS&lt;/TITLE&gt;");
           client.println("&lt;/HEAD&gt;");
           client.println("&lt;BODY&gt;");
           client.println("&lt;H1&gt;FLASHATI&lt;/H1&gt;");
           client.println("&lt;hr /&gt;");
           client.println("&lt;a href=\"/?1\"\"&gt;LED1&lt;/a&gt;");
           client.println("&lt;a href=\"/?2\"\"&gt;LED2&lt;/a&gt;");
           client.println("&lt;a href=\"/?3\"\"&gt;LED3&lt;/a&gt;");
           client.println("&lt;a href=\"/?4\"\"&gt;LED4&lt;/a&gt;");
           client.println("&lt;a href=\"/?5\"\"&gt;LED5&lt;/a&gt;");
           client.println("&lt;a href=\"/?6\"\"&gt;LED6&lt;/a&gt;");
           client.println("&lt;a href=\"/?7\"\"&gt;LED7&lt;/a&gt;");
           client.println("&lt;a href=\"/?8\"\"&gt;LED8&lt;/a&gt;");
           client.println("&lt;br /&gt;");     
           client.println("&lt;br /&gt;"); 
           client.println("&lt;p&gt;Created by Rui Santos. Visit http://randomnerdtutorials.com for more projects!&lt;/p&gt;");  
           client.println("&lt;br /&gt;"); 
           client.println("&lt;/BODY&gt;");
           client.println("&lt;/HTML&gt;");

           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?1") &gt;0){
               ledUno();
            }
           if (readString.indexOf("?2") &gt;0){
               ledDue();
            }
            if (readString.indexOf("?3") &gt;0){
               ledTre();
            }
            if (readString.indexOf("?4") &gt;0){
               ledQuattro();
            }
            if (readString.indexOf("?5") &gt;0){
               ledCinque();
            }
            if (readString.indexOf("?6") &gt;0){
               ledSei();
            }
            if (readString.indexOf("?7") &gt;0){
               ledSette();
            }
            if (readString.indexOf("?8") &gt;0){
               ledOtto();
            }
           readString="";
        }

        }
    }
}
}
</code></pre>

<p>So I came out with this after a lot of research:</p>

<pre><code>/*
    Created by Rui Santos
    Visit: http://randomnerdtutorials.com for more arduino projects

    Arduino with Ethernet Shield
*/

#include &lt;SPI.h&gt;
#include &lt;Ethernet2.h&gt;
#include &lt;SD.h&gt;
File webFile;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte ip[] = { 192, 168, 1, 178 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 };                   // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
EthernetServer server(80);                             //server port     
String readString;
boolean L1chk;
boolean L2chk;
boolean L3chk;
boolean L4chk;
boolean L5chk;
boolean L6chk;
boolean L7chk;
boolean L8chk;
int led;

void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);

    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    // start the Ethernet connection and the server:
    Ethernet.begin(mac);
    server.begin();
    Serial.print("server is at ");
    Serial.println(Ethernet.localIP());
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
}


void loop() {
    // Create a client connection
    EthernetClient client = server.available();
    if (client) {
        boolean currentLineIsBlank = true;
        while (client.connected()) {   
            if (client.available()) {
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' &amp;&amp; currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    webFile = SD.open("index.htm");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }

                        webFile.close();
                    }
                    break;

                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                    if (readString.indexOf("?1") &gt;0){
                        ledUno();
                    }
                    if (readString.indexOf("?2") &gt;0){
                        ledDue();
                    }
                    if (readString.indexOf("?3") &gt;0){
                        ledTre();
                    }
                    if (readString.indexOf("?4") &gt;0){
                        ledQuattro();
                    }
                    if (readString.indexOf("?5") &gt;0){
                        ledCinque();
                    }
                    if (readString.indexOf("?6") &gt;0){
                        ledSei();
                    }
                    if (readString.indexOf("?7") &gt;0){
                        ledSette();
                    }
                    if (readString.indexOf("?8") &gt;0){
                        ledOtto();
                    }
                    readString="";
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
                //controls the Arduino if you press the buttons

            }

        }
        delay(1);      // give the web browser time to receive the data
        client.stop();
        if (readString.indexOf("?1") &gt;0){
            ledUno();
        }
        if (readString.indexOf("?2") &gt;0){
            ledDue();
        }
        if (readString.indexOf("?3") &gt;0){
            ledTre();
        }
        if (readString.indexOf("?4") &gt;0){
            ledQuattro();
        }
        if (readString.indexOf("?5") &gt;0){
            ledCinque();
        }
        if (readString.indexOf("?6") &gt;0){
            ledSei();
        }
        if (readString.indexOf("?7") &gt;0){ 
            ledSette();
        }
        if (readString.indexOf("?8") &gt;0){
            ledOtto();
        }
        readString="";
    }
}


void ledUno(){
    led = 2;
    if (L1chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L1chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L1chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L1chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledDue(){
    led = 3;
    if (L2chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L2chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L2chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L2chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledTre(){
    led = 4;
    if (L3chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L3chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L3chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L3chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledQuattro(){
    led = 5;
    if (L4chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L4chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L4chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L4chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledCinque(){
    led = 6;
    if (L5chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L5chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L5chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L5chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledSei(){
    led = 7;
    if (L6chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L6chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L6chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L6chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledSette(){
    led = 8;
    if (L7chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L7chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L7chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L7chk = 0;
        return;                   //Led 1 acceso           
    }
}

void ledOtto(){
    led = 9;
    if (L8chk == 0){                                             //Il Ledled 1 è Spento
        digitalWrite(led, HIGH); 
        L8chk = 1;
        return;                   //Led 1 acceso           
    }

    if (L8chk == 1){                                             //Il Ledled 1 è Spento
        digitalWrite(led, LOW); 
        L8chk = 0;
        return;                   //Led 1 acceso           
    }
}
</code></pre>

<p>So far the web page is correctly loaded, but the sketch of the LED light logic seems to not work anymore like it was working correctly before. I thought that maybe someone of you guys could help point me in the right direction.</p>
 26276: <p>It looks that I found the solution to my problem, the first skecth was working correctly because  the <strong>SD card is using the pin 4  for his purpose</strong>, so the sketch was working good becuse the SD card was not used here, in the second code where I used th SD card to serve a webpage <strong>was not working anymore not because of the code, but becuse the PIN 4 where I connected a led was used by SDcard</strong> and so it messed up by blinking the LED</p>

<p><strong>DON'T USE PIN4 WITH AN ETHERNET SHIELD IF YOU PLAN TO USE THE SD CARD</strong></p>
