Reputation: 833
I have two domains pointing at one webroot and need to force any traffic to one of those domains.
But, that means all traffic to the other domain can't get to it.
This is my current rule below
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [L,R=301]
The second domain that I want to allow through is edit.example.co.uk
So, I've tried:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.co\.uk$ [NC]
RewriteCond %{HTTP_HOST} !^edit\.example\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [L,R=301]
But no joy, and then I've tried variations on that theme with no luck.
I think maybe conceptually, I'm struggling with the order that these get processed?
Any insights would be very gratefully received!
Upvotes: 1
Views: 33
Reputation: 784938
You should use 2 different redirect rules:
RewriteEngine On
# add https and www to example.co.uk in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.co\.uk)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
# add https to edit.example.co.uk
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^edit\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Make sure to completely clear your browser cache before you test these rules.
Upvotes: 2