apache_conf 强制SSL,强制首选域,支持auto-ssl

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf 强制SSL,强制首选域,支持auto-ssl相关的知识,希望对你有一定的参考价值。

# BEGIN BizBudding Inc
# revised 07/05/2018, @dws122
# these rules force SSL, support cPanel's autossl with Let's Encrypt, and set the preferred domain
# be sure to replace example.com with your FQDN
# we default to non-www

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

# Enforce https SSL/TLS
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/\d+\.BIN_AUTOSSL_CHECK_PL__\.\w+\.tmp$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
# note, if force www then add it here too
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

# Now that we have SSL running, enfore HSTS
# 
# When the web server sends this header, any browser that accesses the site over HTTPS 
# will be unable to access the unsecured HTTP site for the specified length of time 
# (in this case, 31,536,000 seconds, or one year). Therefore, as soon as you enable HSTS, 
# you should not stop using SSL on your site. If you do, returning visitors will be unable 
# to access your site.
#
#Header set Strict-Transport-Security "max-age=31536000" env=HTTPS


# Enforce non-www rules on the domain
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/\d+\.BIN_AUTOSSL_CHECK_PL__\.\w+\.tmp$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

# Enforce www rules on the domain
#RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
#RewriteCond %{REQUEST_URI} !^/\d+\.BIN_AUTOSSL_CHECK_PL__\.\w+\.tmp$
#RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
#RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]


# for date based urls
#RewriteRule ^([0-9]+)/([0-9]+)/(.*)$ https://example.com/$3/ [R=301,NC,L]
# for date based urls ending in .html
#RewriteRule ^([0-9]+)/([0-9]+)/(.*)\.html$ https://example.com/$3/ [R=301,NC,L]
# for urls ending in .html
#RewriteRule ^(.*)\.html$ https://example.com/$1/ [R=301,NC,L]

</IfModule>
# END BizBudding

以上是关于apache_conf 强制SSL,强制首选域,支持auto-ssl的主要内容,如果未能解决你的问题,请参考以下文章

apache_conf 强制SSL

apache_conf WordPress .htaccess配置文件。允许强制SSL,隐藏wp-config.php,标头ETag,GZIP压缩和过期缓存。

apache_conf 强制https

apache_conf 强制HTTPS

apache_conf 强制斜杠

apache_conf 强制https