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 :doc:`here `. .. contents:: Using the CLI ------------- .. note:: SiteWorx users who do not have shell access should contact their hosting provider. #. 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 #. Navigate to the domain's html directory, replacing {unixuser} and {domain.com} with the corresponding information .. code-block:: cd /home/{unixuser}/{domain.com}/html #. Using a text editor create, or open, a file named ``.htaccess``. The following example uses the Vim text editor: .. code-block:: vim .htaccess #. Add the following lines, replacing {domain.com} with the corresponding information: .. code-block:: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://{domain.com} [R,L] #. Save the file, and exit the text editor Using the SiteWorx File Manager ------------------------------- #. Log into SiteWorx from the browser (https://ip.ad.dr.ess:2443/siteworx) #. In SiteWorx, navigate to **File Manager > File Manager (NEW)** .. image:: /images/sw-filemanager-directories.png :alt: directory list #. Click **html**. This opens the html directory for the domain .. image:: /images/sw-filemanager-html.png :alt: html contents #. Click **New Item**. This opens the Create New Item form #. Update the required fields: - **Item Type**: Select **File** - **Item Name**: Type **.htaccess** .. image:: /images/sw-create-new-item.png :alt: create new item form #. Click **Create Now**. This creates the file and refreshes the html directory page .. image:: /images/sw-htaccess-added.png :alt: updated html directory #. Click **.htaccess**. This opens the options page for the .htaccess file .. image:: /images/sw-htaccess-options.png :alt: htaccess options #. Click **Edit**. This opens the edit form for the file #. Add the following lines, replacing {domain.com} with the corresponding information: .. code-block:: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://{domain.com} [R,L] The following example sets automatic https redirects for a domain called example.com .. image:: /images/sw-htaccess-enforce-https.png :alt: force https text #. Click **Save**