'Apache and Spring https redirect to wrong URL

I have a SpringBoot application running on http://localhost:8080/ and Apache. Apache redirects all requests from *:80 to *:443 and 443 to http://localhost:8080.

When I try to access http://domain_name.com/login it redirects me to https://domain_name.comlogin/

Also if i try to access pages without authentication it should redirects me to login page, but it redirects me to https://domain_name.comlogin/ instead of https://domain_name.com/login and the same with /logout

What's the problem with redirecting. Is it with Apache or Spring?

<VirtualHost *:80>
    ServerName domain_name.com
    ServerAdmin admin@domain_name.com

    Redirect permanent / https://domain_name.com/
</VirtualHost>
<VirtualHost *:443>
    SSLEngine On
    SSLProxyEngine On
    ProxyPreserveHost On

    ServerName domain_name.com
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLCertificateFile /etc/apache2/certificate/domain_name.crt
    SSLCertificateKeyFile /etc/apache2/certificate/private.key
    SSLCertificateChainFile /etc/apache2/certificate/chain.crt
</VirtualHost>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source