Skip to content

How to add rewrite rule to spring boot 2.3.1

I have a Spring Boot application based on this example.

Now the question is how can I add rewrite rules to my application that add /index.html when user visit the root URL.

I mean when user visit http://localhost:8080/my-app or http://localhost:8080/my-app/ then I redirect him or her to http://localhost:8080/my-app/index.html.

I found something here, but unfortunately does not work for me, also it seems org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory does not exist in Spring Boot 2.3.1 anymore.



I only need to add a new controller, despite this application does not use MVC, this controller will redirect the / requests to /index.html.

package me.cimply.ask.odata.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

public class AppController {
    public String index() {     
        return "redirect:index.html";
User contributions licensed under: CC BY-SA
9 People found this is helpful