【发布时间】:2016-12-13 05:25:25
【问题描述】:
我有一个网站https://www.example.com 和子域https://sub.example.com。
我的问题是,每当我尝试访问 https://sub.example.com 时,我都会被重定向到 https://www.example.com。但是,当我访问http://sub.example.com 时,我没有被重定向。
我有一个通配符 SSL 证书,它应该允许我使用 https:// 访问我的子域。这两个站点都运行 WordPress,并由 Bluehost 托管。我尝试了许多解决方案,并且两次联系 Bluehost 客户支持均无济于事。我希望能够在启用 SSL 的情况下访问我的主域和子域。
我已根据此处找到的以下解决方案编辑了.htaccess 文件:htaccess redirect domain to https, subdomain to http and www to non-www
# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://sub.example.com%{REQUEST_URI} [R=301,L,NE]
https://my.bluehost.com/hosting/help/766
# Custom subdomain .htaccess SSL + WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^subdomain.maindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
# End custom subdomain .htaccess
# Custom maindomain .htaccess WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# End custom maindomain .htaccess
http://www.wpbeginner.com/wp-tutorials/how-to-add-ssl-and-https-in-wordpress/
我还尝试了主域和子域的全新 WordPress 安装,但没有成功。我不确定还能尝试什么。任何帮助和建议将不胜感激。
【问题讨论】:
-
您需要发布整个
.htaccess文件,包括 WordPress 指令 - 顺序很重要。为什么您似乎引用 Bluehost 帮助文档中的代码示例?您发布的内容中没有任何内容重定向到https://www.example.com?!这表明您的 WordPress 安装存在配置错误。
标签: wordpress .htaccess ssl subdomain