子域上的 http 重定向到主域;子域适用于 https
http on subdomain redirects to main domain; subdomain works with https
我有一个根域 https://example.com
和子域 https://sub.example.com
,以及根域上的正向 SSL example.com
我的问题是,每当我尝试访问 http://sub.example.com
时,我都被正确重定向到 https://example.com
,但是当我访问 https://sub.example.com
时,我没有被重定向。我怎样才能将 https://sub.example.com
重定向到 https://example.com
?
.htaccess
在子域中:
# BEGIN WordPress
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 6 hours"
ExpiresByType image/jpeg "access plus 6 hours"
ExpiresByType image/gif "access plus 6 hours"
ExpiresByType image/png "access plus 6 hours"
ExpiresByType text/css "access plus 6 hours"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/javascript "access plus 6 hours"
ExpiresByType text/html "access plus 10 minutes"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 3 hours"
</IfModule>
Header set X-Endurance-Cache-Level "2"
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
</IfModule>
如有任何帮助或建议,我们将不胜感激。
您的条件只查找 HTTP 请求
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
尝试添加与 HTTPS 相同的规则
RewriteCond %{HTTPS_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
我有一个根域 https://example.com
和子域 https://sub.example.com
,以及根域上的正向 SSL example.com
我的问题是,每当我尝试访问 http://sub.example.com
时,我都被正确重定向到 https://example.com
,但是当我访问 https://sub.example.com
时,我没有被重定向。我怎样才能将 https://sub.example.com
重定向到 https://example.com
?
.htaccess
在子域中:
# BEGIN WordPress
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 6 hours"
ExpiresByType image/jpeg "access plus 6 hours"
ExpiresByType image/gif "access plus 6 hours"
ExpiresByType image/png "access plus 6 hours"
ExpiresByType text/css "access plus 6 hours"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/javascript "access plus 6 hours"
ExpiresByType text/html "access plus 10 minutes"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 3 hours"
</IfModule>
Header set X-Endurance-Cache-Level "2"
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
</IfModule>
如有任何帮助或建议,我们将不胜感激。
您的条件只查找 HTTP 请求
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
尝试添加与 HTTPS 相同的规则
RewriteCond %{HTTPS_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]