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
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
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!
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:
How to enable redirection from HTTP to HTTPS for a domain in Plesk
Applicable to: Plesk for Linux Plesk for Windows Question How to make a website hosted in Plesk use a secure connection over HTTPS permanently? Answer Before enabling permanent HTTPS redirection...
support.plesk.com
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!