将301重定向到https&的最佳方法万维网

时间:2016-12-22 14:55:12

标签: .htaccess redirect mod-rewrite web https

我想重定向301:

http://example.com
http://www.example.com

https://www.example.com

我把这段代码,但它不起作用(错误500)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off           [OR]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/%{REQUEST_URI} [R=301,L, NE]

1 个答案:

答案 0 :(得分:0)

This:

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

Source: this blog

的href

OR

基于this answer

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost>