通过htaccess将所有http和https:// www重定向到https://example.com

时间:2017-11-03 19:18:10

标签: .htaccess redirect mod-rewrite

我有以下htaccess代码:

<IfModule mod_rewrite.c>
# enable Rewrite engine
RewriteEngine on

# redirect http to https
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

我已经完成了从http://https://的重定向,但我也想重定向(出于原因),所有网址从https://wwwhttps < / p>

但我不知道如何做到这一点!

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteEngine on

# http(s) www -> https
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
# http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]