v-moe
v-moe

Reputation: 1443

Multiple domains on one host https and http

I have multiple domains on one host, my .htaccess looks like this

RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]

RewriteCond %{HTTP_HOST}  web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$  /web_2/public/$1 [L]

And it works so far. Now I want only web1.com, not web2.com, to redirect to https. How do I have to change the settings? (I am also thankful for tips about how to change my "implementation" so far, I am new to .htaccess and willing to learn more about it)

Upvotes: 2

Views: 257

Answers (1)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

Try this :

RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST}  web2.com$ [NC]
RewriteRule ^(.*)$  https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So , your rules will look like this :

RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]

RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST}  web2.com$ [NC]
RewriteRule ^(.*)$  https://%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{HTTP_HOST}  web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$  /web_2/public/$1 [L]

Upvotes: 4

Related Questions