我有几个站点作为子域,主域称为 site1.com。我的主域有 *.site1.com
的通配符 ssl 证书。我的子域可以引用为 site2.site1.com
、site3.site1.com
到 siteN.site1.com
。我的主域正确使用证书并在所有页面上强制使用 https,我的子域仅在管理页面上使用 https,我使用的是 wordpress CMS,或者如果我将我的网站引用为 https,我可以强制使用证书://site2.site1.com
、https://site3.site1.com 等
。我想让我的子域作为 https://site2.com
运行。目前我的域名是 http://site2.com
或 http://site1.site2.com
PS:我无权访问 vhost 文件。这是我所有域的 .htaccess 代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>
最佳答案
我找到了一个简单的插件来完成这项工作。这是我的子域的 .htaccess 文件现在的样子:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
#RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots
</IfModule>
关于wordpress - 子域的 .htaccess 规则强制在所有页面上使用 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40713134/