Link to home
Start Free TrialLog in
Avatar of beer9
beer9Flag for India

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Codrut Tambu
Codrut Tambu
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beer9

ASKER

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?
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