user4445866
user4445866

Reputation:

Htaccess rewrite rule and condition

We are now using OpenCart and domain aliasses in DirectAdmin. We now have some rules in our htaccess for redirecting non www to www and non https to https. But this rule is for all domains. We only want to use it for example-1.com

How can we do this? Htaccess we have tried all failled to do this.

This is the current htaccess we have

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

We only want this for example-1 and example 2 also. But now it always redirects to example-1

Upvotes: 0

Views: 1370

Answers (2)

Croises
Croises

Reputation: 18671

I understand you only try to redirect example-1 and example-2 and not other domains. You can use that:

RewriteCond %{HTTP_HOST} (?:^|\.)(example-1\.com|example-2\.com)$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R=301]

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143856

Try:

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

Upvotes: 0

Related Questions