title: Using relative redirect in spring boot fails
body: <h1>Scenario</h1>
  
  <p>I have an spring-boot application which is accessed using context instead domain root:</p>
  
  <ul>
  <li>domain root : <a href="http://app.com" rel="nofollow noreferrer">http://app.com</a></li>
  <li>my app : <a href="http://app.com/organization_a" rel="nofollow noreferrer">http://app.com/organization_a</a> (redirects me to <strong>my app login</strong>)</li>
  <li>my app login : <a href="http://app.com/organization_a/login" rel="nofollow noreferrer">http://app.com/organization_a/login</a> (form is loaded perfectly)</li>
  </ul>
  
  <h1>Problem</h1>
  
  <p>After success login, using the classic configuration:</p>
  
  <pre><code>formLogin()
      .loginPage("/login")
      .defaultSuccessUrl("/my_form")
  </code></pre>
  
  <p>redirects me to : <a href="http://app.com/my_form" rel="nofollow noreferrer">http://app.com/my_form</a> throwing an error because the url must be : <a href="http://app.com/organization_a/my_form" rel="nofollow noreferrer">http://app.com/organization_a/my_form</a></p>
  
  <p>So,  I tried to use relative url (note the dot before /my_form)  <strong>./my_form</strong> instead <strong>/my_form</strong></p>
  
  <pre><code>formLogin()
      .loginPage("/login")
      .defaultSuccessUrl("./my_form")
  </code></pre>
  
  <p>And spring throw me this error : <strong>defaultTarget must start with '/' or with 'http(s)</strong> due to this validation in spring-security-web jar:</p>
  
  <pre><code>//org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler
  public void setDefaultTargetUrl(String defaultTargetUrl) {
      Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultTargetUrl),
              "defaultTarget must start with '/' or with 'http(s)'");
      this.defaultTargetUrl = defaultTargetUrl;
  }
  </code></pre>
  
  <blockquote>
    <p>So, I can say: Classic default success url method does not allow to use relative urls, because if I use root domain , works like charm as in my localhost.</p>
  </blockquote>
  
  <h1>Relative vs Absolute urls</h1>
  
  <p>More info <a href="https://stackoverflow.com/a/39545949/3957754">here</a></p>
  
  <p>I had similar troubles with html and assets in java an other languages like php and nodejs.</p>
  
  <p>Basically if you are using context instead a domain root for your app, you must need to change this:</p>
  
  <pre><code>&lt;link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/&gt;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>&lt;link href="./vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"/&gt;
  </code></pre>
  
  <p>Note the dot before /vendor/bootstrap/...</p>
  
  <p>Without this dot, your assets will not download because the browser request to  urls like :</p>
  
  <ul>
  <li><a href="http://app.com/main.css" rel="nofollow noreferrer">http://app.com/main.css</a></li>
  <li><a href="http://app.com/app.js" rel="nofollow noreferrer">http://app.com/app.js</a></li>
  </ul>
  
  <p>When should it be:</p>
  
  <ul>
  <li><a href="http://app.com/organization_a/main.css" rel="nofollow noreferrer">http://app.com/organization_a/main.css</a></li>
  <li><a href="http://app.com/organization_a/app.js" rel="nofollow noreferrer">http://app.com/organization_a/app.js</a></li>
  </ul>
  
  <h1>Current workarounds</h1>
  
  <ul>
  <li>Use domain or subdomain instead context.
  
  <ul>
  <li>This is laborious because I will need to open a ticket to my ISP for every new app.</li>
  </ul></li>
  <li>Put the entire url in <strong>defaultSuccessUrl</strong> method.
  
  <ul>
  <li>This is awful because my app will not be portable due to I must set the absolute url <strong>before build</strong>:</li>
  </ul></li>
  </ul>
  
  <pre><code>    formLogin()
          .loginPage("/login")
          .defaultSuccessUrl("http://app.com/organization_a/my_form")
  </code></pre>
  
  <h1>Question</h1>
  
  <blockquote>
    <p>Is there a way to use relative redirect in spring security? </p>
  </blockquote>
  
  <p>I am using one of the latest spring boot versions: <strong>2.1.7.RELEASE</strong></p>
  
  <p>Any help or comment are appreciated.</p>
  
  <p>Thanks</p>