1

我有虚拟主机

<VirtualHost 10.10.10.10:80>
     ServerAdmin webmaster@server.com
     ServerName server.com
     ServerAlias subdomain-a.server.com subdomain-b.server.com subdomain-c.server.com subdomain-d.server.com
     DocumentRoot /srv/www/server.com/public_html/
</VirtualHost>

<VirtualHost 10.10.10.10:443>
     ServerAdmin webmaster@server.com
     ServerName server.com
     ServerAlias subdomain-a.server.com subdomain-b.server.com subdomain-c.server.com subdomain-d.server.com
     DocumentRoot /srv/www/server.com/public_html/
</VirtualHost>

我想强制访问者对子域-a 和子域-c 使用 https。subdomain-b 和 subdomain-d 的访问者可以使用 http 和 https。如何配置.htaccess?

4

1 回答 1

1

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

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

RewriteCond %{HTTP_HOST} ^(subdomain-a|subdomain-c)\.server\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
于 2012-05-31T21:51:32.630 回答