I have a multisite installation with 2 sites running off separate domains. One of these sites needs to go through https:// while the the other can stick to http://. I also want all traffic to be rewritten to include the www. prefix.


example.com rewritten to https://www.example.com

example.co.uk rewritten to http://www.example.co.uk

I'm trying to set my .htaccess file to handle this, and have tried with the syntax discussed here.

RewriteEngine on
<If "%{HTTP_HOST} == 'example.com'">
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<If "%{HTTP_HOST} == 'example.co.uk'">
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !http
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Needless to say, it's not working. Any input would be much appreciated!

3 Answers 3


First I would try using the [drupal]/sites/sites.php file to do something like this:

$sites['example.co.uk'] = 'example.com';
$sites['example.com'] = 'example.com'; // for demonstration only

Then check out the htaccess module to force HTTPS. These are the options:

enter image description here


This is untested, but would the following work:

# Force HTTPS for example.com
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [NC,R=301,L]

# Force HTTP for example.co.uk
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [NC,R=301,L]
  • 2
    Hi Colin, thanks a lot for your answer. Unfortunately that's not working either. Looking at it with an htaccess tester it is rewriting the URL to example.com/example.com I've tried a few more things and have a version that works on the htaccess tester, but returns an infinite loop once it's up on the server and I try it there:
    – pepsimxm
    Apr 13, 2015 at 15:02
  • #.com to www RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) example.com/$1 [R=301,L] #.co.uk to www RewriteCond %{HTTP_HOST} ^example\.co\.uk$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) example.co.uk/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) example.co.uk/$1 [R=301,L]
    – pepsimxm
    Apr 13, 2015 at 15:04
  • Think your loop is caused by missing the RewriteCond %{HTTPS} lines Apr 14, 2015 at 13:12

My suggestion is don't change anything except redirect http://example.com to https://example.com with following (

RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

And if you like to redirect https://example.co.uk to http://example.co.ukadd the following line to your.htaccess` file ( but I don't think you need them)

RewriteCond %{HTTP_HOST} ^(www.)?example.co.uk$
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Also, you can try to set them with Htaccess module

Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings.

Drupal tries to provide a one size fits all htaccess for Apache webservers, but this goal is increasingly difficult. This module allows the webmaster to set specific options.

Also, this module is dedicated to webmasters who don't want to manually modify htaccess every time during a version upgrade to use Drupal.

- Set redirection to www or non www.
- Use Followsymlinks or SymlinksIfOwnersMatch.
- HTTPS support (redirect all request to HTTPS or support both protocols).
- Protect core text files (like CHANGELOG.txt) from being viewed.
- Ability to insert Boost htaccess settings
- Add custom rules before Drupal rules.
- Each htaccess is attached to a profile. This way, you can manage several
- htaccess files and deploy the right one to your website.
- Check if htaccess is altered and report in site status .
- List item - Drush integration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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