1

我们有一个带有一个主站点和一个子站点的 WP Multisite 安装。我们刚刚从 Godaddy 购买了 UCC 证书,并希望使用 https 保护整个站点。

我们正在寻找: 将 domain.com 重定向到 www.domain.com 将http://www.domain.com重定向到https://www.domain.com

换句话说,对所有内容强制使用 www 和 https。

我尝试对我们的 .htaccess 文件进行一些修改,但没有成功。似乎会导致 Google Chrome 出现问题。

提前感谢您的任何反馈或建议!

年代克兰斯顿

这是我当前的 .htaccess 文件:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
<IfModule mod_headers.c>
   SetEnvIf Origin "http(s)?://(www\.)?(www.simplymusicteachers.com/wp-admin/admin-ajax.php|www.simplymusicteachers.com)$" AccessControlAllowOrigin=$0$1
   Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
</IfModule>

这是添加了附加代码的文件:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
<IfModule mod_headers.c>
   SetEnvIf Origin "http(s)?://(www\.)?(www.simplymusicteachers.com/wp-admin/admin-ajax.php|www.simplymusicteachers.com)$" AccessControlAllowOrigin=$0$1
   Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
</IfModule>
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## force HTTPS and www. if any of them are not already present
RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L]
4

1 回答 1

4

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## force HTTPS and www. if any of them are not already present
RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L]

确认它工作正常后,替换R=302R=301. R=301在测试你的 mod_rewrite 规则时避免使用(永久重定向)。

编辑如果由于某种原因不支持后视,请尝试:

RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=302,L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.sub.domain.com%{REQUEST_URI} [R=302,L]
于 2013-06-04T18:46:46.170 回答