Redirect http to https

From vpsget wiki
Revision as of 14:03, 5 October 2017 by Vq (talk | contribs)
Jump to: navigation, search

In order to redirect http to https in Apache it's enough to add these lines to .htaccess file in the web root:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

To redirect www http to non-www https, add these lines to .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Please note that for these directives to work Apache conf file should contain allowing rules for the web directory:

<Directory />
   Options FollowSymLinks
   AllowOverride All            
</Directory>


If you have nginx, then you can edit http section of main.conf file:

server {
    listen 80;
    server_name www.domain.com domain.com;
    rewrite (.+) https://vpsget.com$1 permanent;
}