1

I have virtual hosts

<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>

I want to force visitors use https for subdomain-a and subdomain-c. Visitors of subdomain-b and subdomain-d could use http and https. How to configure .htaccess?

dr0zd
  • 1,368
  • 4
  • 18
  • 28
  • There is plenty of example here on SO. Try looking for one that matches a specify host with `%{HTTP_HOST}`. – Gerben May 31 '12 at 17:13

1 Answers1

1

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643