Spring Boot redirect and HTTP 301

Updated:

Migration from Jekyll to Spring Boot without losing SEO value

This blog website is developed using Spring Boot and it has been migrated from Jekyll.

One of the issues was the url change from the Jekyll format: 'year-month-day-title' to a more polished 'title'.

Jekyll includes the permalink property that allows to simply define a custom url. In the most recent posts I used this feature but many old posts already indexed by Google were still using the format with the date.

The goal here is to use a 'permalink' in Spring Boot without losing the Google SEO value of the existing urls.

Solution 1 : Load balancer

A simple solution is to redirect from the old url to the new url using a load balancer, but we want to solve the solution directly in our application to avoid external dependencies.

Spring Boot solution

Spring Boot can redirect the pages using a RedirectView, this solution is very clean and it allows us to 'tell Google' and oder search engines that the pages moved permanently.

This means that they should update their internal reference without removing the SEO value of the URL built during the years.

// GET: marco.dev/2021/01/19/blog-migrated 
@GetMapping(value ="/{year}/{month}/{day}/{title}") 
public RedirectView getPost(@PathVariable("title")String title) { 
     
     RedirectView redirectView = new RedirectView("/"+title); 
    // MOVED_PERMANENTLY tells Google to update his index with the new page url (http 301) 
    redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY); 
    // we send the new url: blog-migrated with the HTTP 301 status 
    return redirectView; 
} 

RedirectView documentation
HTTP 301 Status documentation


Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).