• 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

  • We are developing a new feature in Plesk that will help you promote your websites or business on social media. We want to conduct a one-hour online UX test to present the prototype and collect feedback. If you are interested in the feature, please book a meeting via this link.
    Thank you in advance!
  • 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.

Issue Redirect from www. to non-www and http to https with Plesk Obsidian Apache / Nginx Cloudflare

sall10

Basic Pleskian
Hello,

I’m still struggling to find the perfect redirect solution from www. to non-www and http to https with Plesk Obsidian Apache and Nginx Reverse Proxy, when using LetsEncrypt and Cloudflare as well. I googled around and found so much different snippets and opinions to this topic.


My Actual Configuration:

Under Websites and Domains, I have chosen: Domain without WWW


Security:

SSL/TLS Support: marked

Permanent SEO-safe 301 redirect from HTTP to HTTPS: NOT marked

Certificate for Domain.com selected.





Redirect Code in my hatccess File:

RewriteEngine On

RewriteBase /

RewriteCond %{HTTPS} !=on

RewriteCond %{SERVER_PORT} ^80

RewriteRule (.*) https://domain.com%{REQUEST_URI} [R=301,L]

RewriteRule ^index\.php$ - [L]




Found this Article:





1. Solution: Over Apache and Nginx directives


Enabling HTTPS redirection using additional Apache and nginx directives in Plesk (Any Plesk version on Linux)​

In Plesk, go to Domains > example.com > Apache & nginx Settings.

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

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

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



2. Solution: Via htaccess


Enabling HTTPS redirection via the .htaccess file (Any Plesk version for Linux)​



Note: This solution is applicable only if website is processed by Apache.
In Plesk, go to Domains > example.com > File Manager.

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>

Click OK.




As I use Wp Rocket together with Cloudflare Free Plan this would also a possibility for htaccess:


# Redirect www to non-www

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.domain\.com [NC]

RewriteRule ^(.*)$ https://domain/$1 [L,R=301]


# Redirect non-SSL to SSL

RewriteCond %{HTTPS} !on

RewriteCond %{SERVER_PORT} !^443$

RewriteCond %{HTTP:X-Forwarded-Proto} !https

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]





What is the best way, doing it over apache and nginx directives or just via htaccess? If doing this via apache and nginx directives do I need there add additional lines for Cloudflare?



RewriteCond %{SERVER_PORT} !^443$

RewriteCond %{HTTP:X-Forwarded-Proto} !https



Thanks a Lot!
 
@sall10

I have tried to read the whole config and story - but it is a bit much.

The irony is that your entire issue is probably solved by enabling the "Permanent SEO-safe 301 redirect from HTTP to HTTPS" in Plesk.

Nevertheless, there is a lot going on in your web configuration ........ and I am pretty sure that it is not the best idea to make the web config this complex.

I am surprised that you are using several "tools" that more or less do the same, like CloudFlare and WP rocket (and Nginx, to be complete).

In essence, you should be aware of the following :

1 - CloudFlare and WP Rocket do not work nicely together, (and)
2 - CloudFlare free plans will not give you the speed, config and setup that you would require or expect, (and)
3 - CloudFlare is a complete solution that is essentially based on Nginx - but the free plan does not give you more than you could achieve yourself with Nginx, (and)
4 - WP Rocket is on the Apache level, which makes it rather contradictory - if and whenever possible, requests should not even reach Apache, but should be taken care of by Nginx or another type of proxy (like CloudFlare, which functions as a proxy).

In short, there is something wrong with the entire setup - it is a bit subtoptimal.

Please note that you could use the golden combination of Apache (web server) + Nginx (proxy) + Nginx caching, all on the Plesk instance that you have right now.

External solutions like CloudFlare and/or WP Rocket do not add much value, if you have a proper Nginx (+ Nginx caching) configuration.

I would like to kindly ask you to create a test environment with WordPress - an exact copy of the site on which you use WP Rocket.

If you have that test environment, you can then compare the results when (on the one hand) disabling WP Rocket and/or CloudFlare and (on the other hand) enabling Nginx with static file processing and Nginx caching enabled.

If you nee help, just ask/post on this forum ...... if I have time free, I will answer the questions that you might have.

Kind regards...........
 
Hello Trialotto

Thanks a lot for your reply! I cloned the website now to a other Domain, and set the settings like on the Prod Domain. I took out the redirect code from htaccess and enabled the permanent safe 301 redirect in Plesk. The issue is, when loading the Page during load shortly is shown that the Page is not secure, and switch then afterwards to Secure (Browser Lock). Same when I click on Menu Items or Posts, the Browser Lock disappear, and reappear again…. Do I need maybe additional the https directive for Nginx as well?



I tested now the speed with the Cloned Website as suggested, without WP Rocket, with WP Rocket activated and with WP Rocket and Cloudflare. I measured 3 times for every scenario:

1. Without WP Rocket and Cloudflare

1Vancouver_gtmetrix_without_WP_Rocket_and_Cloudflare.png



2. With WP Rocket

2Vancouver_gtmetrix_with_WP_Rocket.png

3. With WP-Rocket and Cloudflare

3Vancouver_gtmetrix_with_WP_Rocket_and_CLoudflare.png
 
@sall10

You should now disable WP Rocket and CloudFlare ........ and just enable Nginx caching via the WordPress Toolkit - then run the tests again.

Also, when having Nginx caching enabled, just check whether your HTTP requests are not bypassing (Nginx) cache.

What is the URL of your (dev) site?

Kind regards......
 
Thanks, I deactivated yet again Cloudflare and WP Rocket, and restarted Apache and Nginx. I tested then again from closest location London and from Vancouver, without Nginx Caching and with Nginx Caching activated .



Without Nginx Caching Activated
Without Nginx Caching_WP-Rocket_Clousdlare_Disabled.png


Nginx Caching enabled:

Nginx Caching enabled_WP Rocket_Cloudflare_Disabled.png

The Dev Site is Password Protected, how can I send you the credentials?

Thx
 
@sall10

I will send you a PM - keep an eye on your mailbox.

One of the reasons why I suggested to create the "dev" site becomes clear from your pagespeed results, when having WP Rocket and CloudFlare deactivated.

In essence, it should not be necessary to activate all kinds of tools and/or external facilities, if the site in question is already optimized.

It is quite apparent that your site is not all optimal - so, we will work on that.

In addition, I will give you some additional tips to make Nginx work properly with Nginx caching.

Kind regards.......
 
Back
Top