Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How to set www before domain name and after http:// in Spring Boot and JavaScript?

I want to know about redirection of domain. That is I want to add www before domain name. How to achieve this thing in Spring boot and JavaScript.

My URL is : https://example.com/dashboard

I want this: https://www.example.com/dashboard

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think it should be configured in the frontend like apache or proxy (nginx or other).

about 4 years ago · Juan Pablo Isaza Report

0

I would advise to redirect at your web server configuration, outside the Spring Boot aplication. But in case you want to redirect for some specific reason you could add Filter to your Spring Boot Configuration:

@Component
public class RedirectionFilter extends GenericFilterBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        final String host = request.getServerName();
    
        if (!org.apache.commons.lang.StringUtils.startsWithIgnoreCase(host, "www.")) {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            
            //obtain the full requested URL
            StringBuffer requestURL = httpRequest.getRequestURL();
            String queryString = httpRequest.getQueryString();
            if (queryString != null) {
                requestURL.append("?").append(queryString);
            }
            
            //set up redirect
            String redirectURL = requestURL.toString();
            redirectURL = redirectURL.replace(host, "www." + host);
            httpResponse.sendRedirect(redirectURL);
        }  else {
            chain.doFilter(request, response);
        }
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!