Skip to content

Commit 754324e

Browse files
authored
Example WebServer WebServer.ino does not redirect when index.htm does not exist (#9142)
1 parent 9afeaf5 commit 754324e

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libraries/ESP8266WebServer/examples/WebServer/README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ It features
2121
* Only files in the root folder are supported for simplicity - no directories.
2222

2323

24-
25-
2624
## Implementing a web server
2725

2826
The ESP8266WebServer library offers a simple path to implement a web server on a ESP8266 board.
@@ -90,7 +88,7 @@ that actually has only one line of functionality by sending a string as result t
9088
> });
9189
> ```
9290
93-
Here the text from a static String with html code is returned instead of a file from the filesystem.
91+
Here the text from a static string with html code is returned instead of a file from the filesystem.
9492
The content of this string can be found in the file `builtinfiles.h`. It contains a small html+javascript implementation
9593
that allows uploading new files into the empty filesystem.
9694
@@ -100,14 +98,14 @@ Just open <http://webserver/$upload.htm> and drag some files from the data folde
10098
## Registering a function to handle requests to the server without a path
10199
102100
Often servers are addressed by using the base URL like <http://webserver/> where no further path details is given.
103-
Of course we like the user to be redirected to something usable. Therefore the `handleRoot()` function is registered:
101+
Of course we like the user to be redirected to something usable. Therefore the `handleRedirect()` function is registered:
104102
105103
> ```CPP
106-
> server.on("/$upload.htm", handleRoot);
104+
> server.on("/", HTTP_GET, handleRedirect);
107105
> ```
108106
109-
The `handleRoot()` function checks the filesystem for the file named **/index.htm** and creates a redirect to this file when the file exists.
110-
Otherwise the redirection goes to the built-in **/$upload.htm** web page.
107+
The `handleRedirect()` function checks the filesystem for the file named **/index.htm** and creates a redirect
108+
response to this file when the file exists. Otherwise the redirection goes to the built-in **/$upload.htm** web page.
111109
112110
113111

libraries/ESP8266WebServer/examples/WebServer/WebServer.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void handleRedirect() {
4141
TRACE("Redirect...");
4242
String url = "/index.htm";
4343

44-
if (!LittleFS.exists(url)) { url = "/$update.htm"; }
44+
if (!LittleFS.exists(url)) { url = "/$upload.htm"; }
4545

4646
server.redirect(url);
4747
} // handleRedirect()

0 commit comments

Comments
 (0)