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

marked as duplicate by Chris S Aug 21 '14 at 14:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @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 '14 at 13:59
5

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>
  • 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. – SOf Virtual Aug 22 '14 at 14:53
  • That has to do with some other rules. – Florin Asăvoaie Aug 22 '14 at 15:54

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