How To: Set up an HTTP to HTTPS Redirect With .htaccess

An .htaccess file can be used to set up a domain to automatically redirect to https.

Note

It is strongly recommended that domains which are automatically redirected to https have an associated SSL certificate. Not having an SSL associated with the domain may cause 403 errors in the browser, or cause Apache to serve the first vhost, alphabetically, that does have an SSL certificate attached.

Information on how to add an SSL certificate in SiteWorx can be found here.

Using the CLI

Note

SiteWorx users who do not have shell access should contact their hosting provider.

  1. Log in to the server at the CLI as either root (if the Server Administrator), or the SiteWorx account shell user, either via SSH or from the terminal

  2. Navigate to the domain’s html directory, replacing {unixuser} and {domain.com} with the corresponding information

    cd /home/{unixuser}/{domain.com}/html
    
  3. Using a text editor create, or open, a file named .htaccess. The following example uses the Vim text editor:

    vim .htaccess
    
  4. Add the following lines, replacing {domain.com} with the corresponding information:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^.*$ https://{domain.com} [R,L]
    
  5. Save the file, and exit the text editor

Using the SiteWorx File Manager

  1. Log into SiteWorx from the browser (https://ip.ad.dr.ess:2443/siteworx)

  2. In SiteWorx, navigate to File Manager > File Manager (NEW)

    directory list
  3. Click html. This opens the html directory for the domain

    html contents
  4. Click New Item. This opens the Create New Item form

  5. Update the required fields:

    • Item Type: Select File

    • Item Name: Type .htaccess

    create new item form
  6. Click Create Now. This creates the file and refreshes the html directory page

    updated html directory
  7. Click .htaccess. This opens the options page for the .htaccess file

    htaccess options
  8. Click Edit. This opens the edit form for the file

  9. Add the following lines, replacing {domain.com} with the corresponding information:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^.*$ https://{domain.com} [R,L]
    

    The following example sets automatic https redirects for a domain called example.com

    force https text
  10. Click Save