Adam Doupé

Associate Professor, Arizona State University
Director, Center for Cybersecurity and Trusted Foundations

Redirecting a Folder to HTTPS With Apache's Config on Ubuntu

| Comments

I found some information about how to do this on the web, but everything I saw talked about using an .htaccess file. I didn’t want to use an .htaccess file.

Here’s what I had to do in Ubuntu (this was on an old 8.10 server).

  1. Enabled mod_rewrite:

     sudo a2enmod rewrite
    
  2. Add the following in the VirtualHost section of my regular http setup to my config at /etc/apache2/sites-enabled/ :

     RewriteEngine On
     RewriteCond %{SERVER_PORT} 80
     RewriteCond %{REQUEST_URI} ^/foldername/.\*
     RewriteRule ^(.\*)$ https://host.name.com$1 [R,L]
    
  3. Restart Apache:

     sudo service apache2 restart
    

Make sure if you use this to change foldername to the name of the folder where you want to enforce HTTPS and host.name.com to the name of your host.

Comments