Apache HTTP to HTTPS htaccess redirect on CWP – Centos WebPanel Rumi, May 9, 2020 Using Apache as main server (only) : Rewrite rule as follows, this need to be added in your sites .htaccess : RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Forcing non www to www and https : RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] Forcing www to non www and https : RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301] this also add Permanent 301 Redirect. If upper rules doesn’t works for your Websites And Getting “Too Many redirects” then you should consider below htaccess rule. Using Apache as backend server behind NGINX/VARNISH server : This need to be added in your sites .htaccess : Rewrite rule as follows, this need to be added in your sites .htaccess : SetEnvIf X-Forwarded-Proto "https" HTTPS=on RewriteEngine on RewriteCond %{HTTPS} !=on RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] OR RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] OR RewriteCond %{HTTP:X-Forwarded-Proto} =https RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] To force all traffic to use both the www domain and SSL HTTPS, use the following rules: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} !=on RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] To force all traffic to use non www domain and SSL HTTPS, use the following rules: RewriteEngine On RewriteCond %{HTTP_HOST} ^domain\.tld$ [OR] RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ SetEnvIf X-Forwarded-Proto "https" HTTPS=on RewriteCond %{HTTPS} !=on RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC] RewriteRule ^ https://domain.tld/$1 [L,R=301] OR RewriteEngine On RewriteCond %{HTTP_HOST} ^domain\.tld$ [OR] RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ SetEnvIf X-Forwarded-Proto "https" HTTPS=on RewriteCond %{HTTPS} !=on RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] replace “domain\.tld” with domain name and tld eg “mysterydata\.com” Related Administrations Configurations (Linux) CentOS Web PanelCWPCWP Panel
Converting laptop into a wifi router March 26, 2016 Well, first assuming, that the laptop has 2 NIC- one with an ethernet port for wired and the other- of course the Wifi ethernet (without this presume this content won’t exist otherwise 😉 ) Now, the next thing- either you get internet from the wired port or to be in… Read More
Using FastCGI with Nginx for Performance on a VM November 11, 2012November 11, 2012 This weekend I decided to play around with the configuration on my Rackspace Cloud Server. Since our various websites have been doing well lately, the relatively low-powered machine I am running on is starting to fill up its available RAM. So far so good but as everyone quickly learns –… Read More
Configure Additional IP Addresses January 18, 2009 Let’s assume our network interface is eth0. Then there is a file /etc/sysconfig/network-scripts/ifcfg-eth0 which contains the settings for eth0. We can use this as a sample for our new virtual network interface eth0:0: cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0 Now we want to use the IP address 192.168.0.101 on the virtual interface eth0:0…. Read More