Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

274
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda