• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • 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.

cannot redirect https://example.com to https://www.example.com

Gauthier

New Pleskian
This is on:

OS: ‪CentOS Linux 7.2.1511 (Core)‬
Plesk version: 12.5.30 Update #27

My ssl certificate is for www.example.com

Using the "Additional directives for HTTP " text area in plesk, I can redirect http://example.com and http://www.example.com, both to httpS://www.example.com.

I also want to redirect https://example.com to https://www.example.com

But the "Additional directives for HTTPS" text area is apparently not working. I fill it with:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}

Checked it was actually wrote to the vhost_ssl.conf, and restarted apache.

As far as I know this should be rewriting https://example.com to https://www.example.com but it just does nothing.

Actually, I found out that WHATEVER I put in "Additional directives for HTTPS" will only be executed if:

1.- the connection is on https protocol (ok)
2.- the url starts with "www." (not ok, I precisely need to add www. if missing)

Please help
 
Hi Gauthier,

Are you running Nginx too?
If so try adding...

Additional nginx directives

Code:
if ($host ~* ^domain.tld$) {
    rewrite ^(.*)$ https://www.domain.tld$1 permanent;
}

Let me know how you get on.
Regards

Lloyd
 
Thanks for quick reply.

nginx is installed. nginx -v returns nginx/1.9.4

In plesk, I removed the apache directives and fill the "Additional nginx directives" with:

if ($host ~* ^example.com$) {
rewrite ^(.*)$ https://www.example.com$1 permanent;
}

I ran "nginx -s reload" and restart apache. Clear cache of the browser.

https://example.com is still not redirected.
 
I also found out the following:

Add an ssl exception on firefox to access https://example.com and got a 403 error.

Forbidden
You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

But the https://www.example.com works fine.

Maybe this error can put us on the way to the misconfiguration ?
 
Back
Top