-4

I have one serveur with multiple domains. I'd like to redirect only one "site-internet.com" to ssl configuration.

I'd like to do :

This is my apache conf file

NameVirtualHost *:80

<VirtualHost *:80>
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^test.site-internet\.com$[NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ http://test.site-internet.com/$1 [NC,R=301,L]

    RewriteCond %{HTTP_HOST} ^(.*)\.site-internet\.com$
    RewriteCond %{HTTP_HOST} ^site-internet\.com$
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301]
</VirtualHost>

But this don't work. What should I correct ?

1
  • @LatinSuD The "NC" flag is just one flag, not two separate flags. It's all very well documented on Apache's website, so there's no need for random baseless guessing.
    – Chris S
    Aug 21, 2014 at 13:59

1 Answer 1

6

So when you put 2 RewriteConds, they are "AND"-ed, meaning they both need to be true in order to apply the RewriteRule. You need to use [OR] to overcome this. Also, I don't get why you need the code for "not redirecting".

<VirtualHost *:80>
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^www\.site-internet\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^site-internet\.com$
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301]
</VirtualHost>
2
  • This work like a charm for www and non www to redirect to https but when I am trying to access test.site-internet.com, I am redirected to www.site-internet.com even after cleared browser cache. Aug 22, 2014 at 14:53
  • That has to do with some other rules. Aug 22, 2014 at 15:54

Not the answer you're looking for? Browse other questions tagged .