I have Apache(ubuntu) server and I need to force https just for sub1.domain.com. Currently all traffic are being forwarded

RewriteEngine On                                     
RewriteCond %{HTTPS} off                             
RewriteRule (.*) xxxx://%{HTTP_HOST}%{REQUEST_URI}

The thing is my server is accessible on multiple domain like:


I only need to force https on one subdomain of my primary domain sub1.domain.com

I have no idea how to write commands in .htaccess

PS: i wrote xxxx as this won't allow me to write https :/


You can do this by adding another condition for that specific host on the server variable %{HTTP_HOST} ([NC] means no case and makes the test case-insensitive):

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com [NC]
RewriteRule (.*) xxxx://%{HTTP_HOST}%{REQUEST_URI}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.