Redirection rule for HTTP to HTTPS?

I am trying like this:

RewriteCond %{HTTP:X-FORWARDED-PROTO} !https
RewriteRule ^(.*)$ https://54.10.10.10:8443$1 [L]

Open in new window


when I access http://54.10.10.10/app  then first I see https://54.10.10.10:8443/app in my browser then I see URL changed as https://54.10.10.10/app. I would like to understand what is causing it to first show port 8443 then hiding it
beer9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Codrut TambuSr. Software Developer EngineerCommented:
search for redirectPort in tomcat config; if value is 8443, than this is the reason => it's an auto-redirect.
=>it results that .htaccess can be changed to the following example, and it will still work the same on port 8443. :
RewriteCond %{HTTP:X-FORWARDED-PROTO} !https
RewriteRule ^(.*)$ https://54.10.10.10$1 [L]

Open in new window


Here's an except from the Tomcat documentation:
redirectPort      

If this Connector is supporting non-SSL requests, and a request is received for which a matching <security-constraint> requires SSL transport, Catalina will automatically redirect the request to the port number specified here.


Full documentation can be found here:
http://tomcat.apache.org/tomcat-8.0-doc/config/http.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beer9Author Commented:
I see something like this in server.xml

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
         maxHttpHeaderSize="65536"
         compression="on"
         compressionMinSize="2048"
         noCompressionUserAgents="gozilla, traviata"
         compressableMimeType="text/html,text/xml,text/plain,text/css,
         text/javascript,text/json,application/x-javascript,
         application/javascript,application/json"
         URIEncoding="UTF-8"/>

Open in new window


and

    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Open in new window


and

        <Connector port="8443" protocol="HTTP/1.1" connectionTimeout="1800000" SSLEnabled="true"
        maxThreads="200" acceptCount="100" scheme="https" secure="true"
        keystoreFile="/share/apps/apache-tomcat/current/conf/server.keystore" keystorePass="tomcat" keyAlias="tomcat"
        clientAuth="false" sslProtocol="TLS" compression="on" compressionMinSize="1024"
    maxHttpHeaderSize="65536"
        compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css,application/javascript,application/json"
    URIEncoding="UTF-8"/>

Open in new window


What does it mean?
0
Codrut TambuSr. Software Developer EngineerCommented:
Your question was:
I would like to understand what is causing it to first show port 8443 then hiding it

Answer:
The cause of the show/hide is that you have manually specified the https port in your .httacces file
RewriteRule ^(.*)$ https://54.10.10.10:8443$1 [L]
so that the 8443 port is enforced upon first request, than the auto-redirect takes place and the port is hidden.

The 8443 port is the default SSL redirectPort to which is set the auto-redirection, you can see it in your config. And as I've mentioned in the earlier post:
If this Connector is supporting non-SSL requests, and a request is received for which a matching <security-constraint> requires SSL transport, Catalina will automatically redirect the request to the port number specified here. (redirectPort)

Optionally, you can take look at: A Simple Step-By-Step Guide To Apache Tomcat SSL Configuration
https://www.mulesoft.com/tcat/tomcat-ssl
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.