8000 Example WebServer WebServer.ino does not redirect when index.htm does not exist by mathertel · Pull Request #9142 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Example WebServer WebServer.ino does not redirect when index.htm does not exist #9142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions libraries/ESP8266WebServer/examples/WebServer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ It features
* Only files in the root folder are supported for simplicity - no directories.




## Implementing a web server

The ESP8266WebServer library offers a simple path to implement a web server on a ESP8266 board.
Expand Down Expand Up @@ -90,7 +88,7 @@ that actually has only one line of functionality by sending a string as result t
> });
> ```

Here the text from a static String with html code is returned instead of a file from the filesystem.
Here the text from a static string with html code is returned instead of a file from the filesystem.
The content of this string can be found in the file `builtinfiles.h`. It contains a small html+javascript implementation
that allows uploading new files into the empty filesystem.

Expand All @@ -100,14 +98,14 @@ Just open <http://webserver/$upload.htm> and drag some files from the data folde
## Registering a function to handle requests to the server without a path

Often servers are addressed by using the base URL like <http://webserver/> where no further path details is given.
Of course we like the user to be redirected to something usable. Therefore the `handleRoot()` function is registered:
Of course we like the user to be redirected to something usable. Therefore the `handleRedirect()` function is registered:

> ```CPP
> server.on("/$upload.htm", handleRoot);
> server.on("/", HTTP_GET, handleRedirect);
> ```

The `handleRoot()` function checks the filesystem for the file named **/index.htm** and creates a redirect to this file when the file exists.
Otherwise the redirection goes to the built-in **/$upload.htm** web page.
The `handleRedirect()` function checks the filesystem for the file named **/index.htm** and creates a redirect
response to this file when the file exists. Otherwise the redirection goes to the built-in **/$upload.htm** web page.



Expand Down
< 5557 td id="diff-6bb678326063e6902d280cf452e946f8177e38fef301bcce37c5b1fc151e10f8L41" data-line-number="41" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void handleRedirect() {
TRACE("Redirect...");
String url = "/index.htm";

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

server.redirect(url);
} // handleRedirect()
Expand Down
0