I am running Apache 2.4.7 on Ubuntu 12.04. I have a site http://bharatkrishna.net/ and this is running off a machine at my home. I have forwarded ports 80 & 443 on my router.

As you can see, when you visit http://bharatkrishna.net/, it automatically gets redirected to https://bharatkrishna.net/.

I do not want it to get redirected to https for the whole site. I had intended to do it only for a particular sub-URL. ie. like only http://bharatkrishna.net/login should be https, rest should be http. How do I do it?

This is how I set up SSL on Apache by reading some tutorials online :

• In /etc/apache2/sites-enabled/ turn on SSLEngine, set cert locations

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost                                                                                                                                                                                               
                DocumentRoot /var/www/html/

                #LogLevel info ssl:warn                                                                                                                                                                                                       

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

                #   SSL Engine Switch:                                                                                                                                                                                                        
                #   Enable/Disable SSL for this virtual host.                                                                                                                                                                                 
                SSLEngine on

                SSLCertificateFile      /etc/apache2/ssl/www_bharatkrishna_net.crt
                SSLCertificateKeyFile   /etc/apache2/ssl/bharatkrishna.net.key

                SSLCACertificatePath /etc/ssl/certs/
                SSLCACertificateFile /etc/apache2/ssl/bundle.crt

....
....

        </VirtualHost>
</IfModule>

• Run the following commands:

sudo a2enmod ssl
sudo a2ensite default-ssl

I copied 000-default.conf to default.conf under sites-enabled and here is the contents of the file:

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

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

closed as off-topic by Tero Kilkanen, fukawi2, mdpc, fuero, MadHatter Mar 3 '15 at 10:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Tero Kilkanen, fukawi2, mdpc, fuero, MadHatter
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    None of this shows anything that would cause a redirect. Include your configuration for port 80 – ETL Mar 2 '15 at 3:54
  • @ETL, I have added my config for port 80 to the OP. Thanks. – Bharat Mar 2 '15 at 4:24
  • 4
    I don't see anything doing redirect to https and I tried the link and it does not redirect me to https so I don't think you are having an issue. If you are redirected to https it might be that you are using Google Chrome and it checks if https is available and if so, switch (I believe I read somewhere once that Chrome does that). – ETL Mar 2 '15 at 4:28
  • 1
    yes it is Chrome! :-| I tried it on firefox and it stays in http. In Chrome even in incognito mode it switches to https. – Bharat Mar 2 '15 at 4:43
up vote 5 down vote accepted

The configuration posted for Apache does not do any redirect from http to https. The switch to https is done by the browser in this case.

More information on this behavior can be found at:

Not the answer you're looking for? Browse other questions tagged or ask your own question.