Blame | Last modification | View Log | RSS feed
// SPDX-License-Identifier: LGPL-3.0-or-later// Copyright 2016-2026 Hristo Gochkov, Mathieu Carbou, Emil Muratov, Will Miles//// Shows how to rewrite URLs//#include <Arduino.h>#if defined(ESP32) || defined(LIBRETINY)#include <AsyncTCP.h>#include <WiFi.h>#elif defined(ESP8266)#include <ESP8266WiFi.h>#include <ESPAsyncTCP.h>#elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)#include <RPAsyncTCP.h>#include <WiFi.h>#endif#include <ESPAsyncWebServer.h>static AsyncWebServer server(80);void setup() {Serial.begin(115200);#if ASYNCWEBSERVER_WIFI_SUPPORTEDWiFi.mode(WIFI_AP);WiFi.softAP("esp-captive");#endif// curl -v http://192.168.4.1/index.txtserver.on("/index.txt", HTTP_GET, [](AsyncWebServerRequest *request) {request->send(200, "text/plain", "Hello, world!");});// curl -v http://192.168.4.1/index.txtserver.on("/index.html", HTTP_GET, [](AsyncWebServerRequest *request) {request->send(200, "text/html", "<h1>Hello, world!</h1>");});// curl -v http://192.168.4.1/server.rewrite("/", "/index.html");server.rewrite("/index.txt", "/index.html"); // will hide the .txt fileserver.begin();}// not neededvoid loop() {delay(100);}