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

271
Visualizações
Force SSL + www + Subdirectory with .htaccess

I have the following domains:

http://example.net    -> https://www.example.com/
http://example.org    -> https://www.example.com/
http://example.com    -> https://www.example.com/
http://theexample.com -> https://www.example.com/

I'm lost looking for a way to be able to force redirect all these domains to a single domain that uses www and https including all subdirectories. The main domain is example.com and I need to redirect it including subdirectories like:

http://example.net/blog     -> https://www.example.com/blog
http://www.example.org/blog -> https://www.example.com/blog
https://example.com/blog    -> https://www.example.com/blog
http://theexample.com/blog  -> https://www.example.com/blog

https://www and the domain example.com is mandatory all subdirectories.

Thank you in advance for your help

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

0

Rather than checking for the hostnames to redirect, you could instead just check that the scheme + hostname is not the canonical and then redirect to it. So, if the request is not for https://www.example.com/... then redirect (copying the URL-path).

For example:

RewriteEngine On

RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule (.*) https://www.example.com/$1 [R=302,L]

The above states... for all requests where HTTPS is either off or not www.example.com then redirect to https://www.example.com/<URL-path>. $1 is a backreference to the capturing subgroup in the RewriteRule pattern (ie. the URL-path). Any query string is also copied through by default.

The = prefix on the CondPattern makes this an exact string match, not a regex. And the ! prefix negates the regex (ie. does not match).

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