Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
.htaccess redirect any domain to a domain apart from a specific domain, rule

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!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda