• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved Single redirect of non-www to www through https/ssl (redirect all to https://www.*)

Shawn

New Pleskian
I am trying to create single redirects for variations of my webpage.

For example:

example.com
www.example.com
https://example.com

Each uses a single redirect to https://www.example.com

I went to Websites & Domains --> Apache & nginx Settings

For "Additional directives for HTTP" I added the following:
Code:
ServerName example.com
ServerAlias www.example.com
Redirect 301 / https://www.example.com/

So far it is working as all http:// requests are sent to https://www.example.com/

However, what configuration do I need for "Additional directives for HTTPS" so that https://example.com is sent to https://www.example.com?


PS nginx settings are Proxy mode
 
Here is an example of my redirects before Subscriptions > Your subscription > Hosting Settings > Preferred domain > Choose the "www.*" option.



Here is an example of my redirects after the "www.*" option.



I used this tool here to test redirects: https://varvy.com/tools/redirects/

As you can see, choosing the "www.*" option solves one problem. That is it redirects https://example.com to https://www.example.com

However, this option also creates two redirects for http://example.com to https://www.example.com.

I came across "additional directives for http" and "additional directives for https" and think if I set this up correctly it might work. Currently with the setup I described in the first post, there is only one redirect from http://example.com to https://www.example.com

I would like single redirects and need a configuration to redirect https://example.com to https://www.example.com
 
Last edited:
No, it does not. It only redirects from the non-www to the www version. The redirect from the non-SSL to SSL comes from another directive or setting. That is also the reason why more than one redirect is happening.

Exactly. My first http directive is causing the following chain when that setting is enabled:
http://example.com to https://example.com to https://www.example.com

I need one redirect for all variations of URL to www. + SSL (https://www.*)

My current setup redirects http://example.com and http://www.example.com to https://www.example.com (with the http directive via one redirect).

However, I need a unique directive to send https://example.com to https://www.example.com
 
Last edited:
I see what you want. I didn't get it from your initial post. You want something like

<If "%{HTTP_HOST} != 'www.example.com' || %{SERVER_PROTOCOL} != 'HTTPS'">
Redirect "/" "https://www.example.com/"
</If>

Have you tried that? It should redirect anything to https://www in one request. I've never combined two conditions in a single statement. According to Apache the Backus-Naur notation can be used, but not sure if this will really work. It needs at least Apache 2.4.
 
I found a solution. It is all being configured with VirtualHost. One for port 80 and one for port 443 (one for SSL and one for non-SSL)

To enable a Single Redirect for all variations of a website to https://www.* the following settings should be applied in "Websites and Domains" --> "Apache & nginx Settings"

Additional directives for HTTP:

Code:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com$1 [R=301,L]

Additional directives for HTTPS:

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) https://www.example.com$1 [R=301,L]
 
Hello,
I have the same issue on one website (wordpress) and followed your suggestion, but it did not work. In fact, I am using "none" in Plesk subscription hosting settings (but https://www... in wordpress settings) and already everything is redirected except for the home page.

With or without the additinal http and https directives makes no difference.
I also have a www CNAME record correctly pointing to main domain.

Other cases configured the same way work fine.

My config is nginx with PHP-FPM; Plesk is 17.8.11 Update #61

Any hint, please?

Best regards

Franco
 
Back
Top