package com.example.spring.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.resource.VersionPathStrategy;

@Slf4j
public class MiddleVersionPathStrategy implements VersionPathStrategy {
    private final String prefix;
    private final String version;

    public MiddleVersionPathStrategy(String prefix, String version) {
        this.prefix = prefix;
        this.version = version;
    }

    @Override
    public String extractVersion(String requestPath) {
        if (requestPath.startsWith(this.prefix)) {
            String prefixRemoved = requestPath.substring(this.prefix.length());
            if (prefixRemoved.startsWith(this.version)) {
                return this.version;
            }
        }
        return null;
    }

    @Override
    public String removeVersion(String requestPath, String version) {
        return requestPath.substring(this.prefix.length()).substring(this.version.length());
    }

    @Override
    public String addVersion(String path, String version) {
        log.info("addVersion: {}", path);
        if (path.startsWith(".")) {
            return path;
        } else {
            return (path.startsWith("/") ? this.prefix + this.version + path : this.prefix + this.version + "/" + path);
        }
    }
}

@@ -864,16 +864,30 @@
   return
+ this.prefix +
  request
@@ -925,20 +925,11 @@
 th()
-).substring(
+ + 
 this
@@ -1165,20 +1165,42 @@
     
-return (path
+String p = path;%0A            if (p
 .sta
@@ -1215,88 +1215,263 @@
 %22/%22)
- ? this.prefix + this.version + path : this.prefix + this.version + %22/%22 + path);
+) %7B%0A                p = p.substring(1);%0A            %7D%0A            if (p.startsWith(this.prefix)) %7B%0A                return this.prefix + this.version + %22/%22 + p.substring(this.prefix.length());%0A            %7D else %7B%0A                return path;%0A            %7D
 %0A   

Fix fixed version example to handle prefix correctly