• 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

Resolved Redirect non-www to www subdomain

imartin83

New Pleskian
Server operating system version
ubuntu 22.04
Plesk version and microupdate number
Plesk Obsidian Web Host Edition 18.0.47
Hello guys,
I little help will do great. :)
Issue:
blog.domain.com --> www.blog.domain.com= Google stays happy :)

- I have migrated a web with a subdomain www.blog.domain.com to plesk.
- Created an FTP folder for blog.domain.com (with no www).
- In DNS on Cloudflare pointed to it via records: A record "www.blog" to IP; A record "blog" to IP; CNAM "www" to @; wildcard * A record to @.
- In the database the home URL is set as https://blog.domain.com (used to be with "www", but now does not resolve if used "www")
- SSL certificate is installed via Let's encrypt in Plesk (Cloudflare Free does not support 3rd level subdomains like "www.blog")

Issue 1: Non-www subdomain is working OK. www.blog is not working ("Site can't provide secure connection - ERR_SSL_VERSION_OR_CIPHER_MISMATCH").
Issue 2: Redirection to WWW is not working, when editing .htaccess file of the subdomain. I cannot even do the vice versa, redirect the non-www to www.
Used redirection in subdomain folder:
RewriteCond %{HTTP_HOST} !^blog\.domain\.cz$ [NC]
RewriteRule ^(.*)$ https://blog.domain.cz/$1 [R=301,L]

The subdomain is under the main domain, so it has no option to set preferred display with or without "www" in plesk. Kindda confused with all the redirections, SSLs and crazy things. Why make it simple, if it can be complex.

Thanks for any idea.
Regards
Martin
 
SOLVED!

Ok, after a bit of digging.
This was a TLS version option in Plesk it seems. In Domains > domain.com > SSL/TLS > TLS Versions and applied preset should be set to Modern (default is intermediate). If TLS is managed in Cloudflare, then I think it should be only with a purchased certificate. So, this concerns only free Let's Encrypt in Plesk.

Also, subdomain redirect was changed to:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

This should be placed in .htaccess of the subdomain, at the top, before anything else. This is only if in Cloudflare Proxy is turned OFF for the DNS record www.subdomain. i think it can mess things up, not sure though.

If proxy is ON, another redirection can be set:

<IfModule mod_rewrite.c>
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

I just did not have time and the nerves to try the proxy setup if it is OK with Cloudflare.
Also, in the database I set back the home URL to be with "www" and "https", as the redirect will not work otherwise.

Hope it helps for those lost souls out there. :)
Martin
 
Back
Top