• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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