Difference between revisions of "Redirect http to https"
Line 4: | Line 4: | ||
RewriteCond %{HTTPS} !on | RewriteCond %{HTTPS} !on | ||
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} | RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} | ||
+ | |||
+ | To redirect www http to non-www https ad 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; | ||
+ | } | ||
[[Category:Linux]] | [[Category:Linux]] |
Revision as of 14:02, 5 October 2017
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 ad 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; }