Articles in this section

How to enable redirection from HTTP to HTTPS for a domain in Plesk?

Plesk for Windows kb: how-to Plesk for Linux ABT: Group B

Applicable to:

  • Plesk for Linux
  • Plesk for Windows

Question

  • How to make a website hosted in Plesk use a secure connection over HTTPS permanently?

Answer

Follow the steps below in order to enable the HTTP to HTTPS redirection for a website hosted in Plesk successfully:

  1. Log into Plesk

  2. Make sure that the website is accessible over HTTPS by covering the following requirements:

  3. Afterwards, go to Domains > example.com > Hosting & DNS > Hosting

  4. Enable the setting Redirect visitors from HTTP to HTTPS via a SEO friendly 301 redirect and select your certificate from the drop-down menu and press Save

    Note: If the setting Redirect visitors from HTTP to HTTPS via a SEO friendly 301 redirect is grayed out for you, please contact your service provider for assistance with permanent HTTPS redirection.

After this has been done, redirection from HTTP to HTTPS will be happening automatically for your website.

Alternatively, if you cannot follow the steps above for some reason, you may achieve the same result by using one of the alternative solutions provided below:

Alternative solutions for Linux

Click on a section to expand

Enabling HTTPS redirection using additional Apache and nginx directives in Plesk (For Linux)
  1. Log in to Plesk.

  2. Go to Domains > example.com > Apache & nginx Settings.

  3. Copy the following directives to the Additional directives for HTTP field:

    Note: If you are a domain owner and Apache & nginx Settings is not available for you, please contact your service provider for assistance with permanent HTTPS redirection.

    CONFIG_TEXT: <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,QSA]
    </IfModule>

  4. Copy the following directives to the Additional nginx directives field, if nginx is used:

    CONFIG_TEXT: if ($ssl_protocol = "") {
    rewrite ^/(.*) https://$server_name/$1 permanent;
    }

Enabling HTTPS redirection via the .htaccess file (For Linux)

Note: This solution is applicable only if the website is processed by Apache.

  1. Log in to Plesk.

  2. Go to Domains > example.com > File Manager.

  3. Open the .htaccess file, if available, or create a new one: click > Create File > type .htaccess in the File Name field > click OK. Once created, click on the file and paste the following content:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,QSA]
    </IfModule>

  4. Click OK.

Enabling HTTPS redirection via Plesk CLI commands (For Linux)
  1. Log into your server via SSH

  2. To enable SSL support for a domain, execute the following command:

    # plesk bin site -u example.com -ssl true

  3. To enable or disable HTTP to HTTPS redirection for a domain, execute one of the following command:

    # plesk bin site -u example.com -ssl-redirect true

  4. To set a specific SSL certificate for use on the domain, execute the following command:

    Note: Replace testcert with the actual name of the certificate that you want to assign.

    # plesk bin site -u example.com -certificate-name testcert

Alternative solutions for Windows Server

Click on a section to expand

Enabling HTTPS redirection via domain's web.config file (For Windows Server)

 

  1. Log in to Plesk.

  2. Go to Domains > example.com > File Manager and open the web.config file.

  3. Paste the following content right before </system.webServer>:

    Note: If the <rewrite>/<rules> sections already present in the web.config file, put the content below without tags <rewrite><rules>... </rules></rewrite> inside existing <rules> section.

    CONFIG_TEXT: <rewrite>
    <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
    </rules>
    </rewrite>

    Click on the picture to enlarge
    Code Editor

Enabling HTTPS redirection in IIS Manager (For Windows Server)
  1. Connect to a Plesk server via RDP.

  2. Start Internet Information Service (IIS) Manager at Windows Start > All Programs > (Windows) Administrative Tools.

  3. In IIS Manager, expand SERVERNAME > Sites > click on a required site name > double-click URL Rewrite.

    Note: If the URL Rewrite button is missing, install the component "IIS URL Rewrite Module" using this KB article.

  4. Click Add rule(s)... on the right pane > under the Inbound rules select Blank rule and click OK:


    Add_Rule_s_.PNG

  5. Configure the new rule:

    • Set the rule name in the field Name.

    • Match URL section
      • Requested URL: Matches the Pattern
      • Using: Regular Expressions
      • Pattern: (.*)


        Edit_Inbound_Rule.PNG

    • Conditions section

      Expand the Conditions section > click Add... and fill in the fields:
      • Condition input: {SERVER_PORT_SECURE}
      • Check if input string: Matches the Pattern

      • Pattern: ^0$


        Add_Condition.PNG

    • Action section:
      • Action type: Redirect
      • Redirect URL: https://{HTTP_HOST}{REQUEST_URI}
      • Redirect type: Permanent (301)


        Capture.PNG

    • Click Apply on the right pane to save the rule.

Was this article helpful?

Comments

1 comment
Date Votes
  • Could you please also state the CLI command to change this setting on Linux?

    0

Please sign in to leave a comment.