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.
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
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:vim .htaccess
Add the following lines, replacing {domain.com} with the corresponding information:
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)
Click html. This opens the html directory for the domain
Click New Item. This opens the Create New Item form
Update the required fields:
Item Type: Select File
Item Name: Type .htaccess
Click Create Now. This creates the file and refreshes the html directory page
Click .htaccess. This opens the options page for the .htaccess file
Click Edit. This opens the edit form for the file
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
Click Save